Thread: Type checking & Flexibility

  1. #1
    Registered User
    Join Date
    Dec 2013
    Posts
    1

    Type checking & Flexibility

    What is the meaning of type checking in array?


    which better array of Flexibility ?
    in java OR C++

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Arrays in both Java and C++ are homogeneous. That means that each element is the same type. There are heterogeneous array, but they aren't natively supported by either language. This does not mean though that in languages that have heterogeneous arrays that type checking will not take place. I haven't found heterogeneous arrays to be much more useful than their homogeneous counterparts. That's an opinion though, and likely has to do with studying languages that don't have the mixed type arrays.
    Other than that, I really don't know what you mean.

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    I guess what you're talking about is that in Java you can have an array that doesn't specify the generic parameter, effectively making an array of Objects. In C++ you can't, although you can have an array of void pointers if you were ever inclined, to achieve a similar effect. (More advanced trickery is needed but possible for proper polymorphic behavior)

    But you almost never need an array that can hold any type (or pointers to any type), so this Java "feature" leads to more errors than usefulness. Type checking is a tool for making obvious logic errors into compile-time errors, and Java's unsafely here can hide errors. At least it does until the program is tested, since the runtime type checks will still fire.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Flexibility with reading one or two strings?
    By bungkai in forum C Programming
    Replies: 16
    Last Post: 07-10-2011, 01:34 AM
  2. Type checking
    By h3ro in forum C++ Programming
    Replies: 16
    Last Post: 05-10-2008, 04:36 PM
  3. type checking?
    By wolfindark in forum C++ Programming
    Replies: 12
    Last Post: 12-15-2007, 11:04 PM
  4. type checking
    By white in forum C Programming
    Replies: 1
    Last Post: 10-24-2005, 12:44 PM
  5. Type checking
    By Araenor in forum C Programming
    Replies: 10
    Last Post: 08-29-2001, 12:47 AM

Tags for this Thread