Re: Cannot find symbol java error (newbie question)



Daniel Pitts wrote:
Look at this SSCCE:

class MyClass {
Integer[] array = new Integer[10];

public void doSomething() {
array.intValue(); /* fails, calling on the array instead of the
element */
array[0].intValue(); /* succeeds */
for (int i = 0; i < array.length; ++i) {
System.out.println(array[i].intValue()); /* succeeds */
}
}
}

These calls marked "succeeds", while they successfully compile, only succeed at runtime if each invoked array element is non-null.

This is not relevant to the compilation issue but might be important to those who forget that newsgroup examples sometimes intentionally omit details for pedagogical purposes that would be problematic in actual production. In production code one would anticipate a NullPointerException.

--
Lew
.



Relevant Pages

  • Re: Unpack - getting values directly into the correct variables
    ... redundant, yes, but I've seen much worse code. ... Maybe a bit too clever for production code. ... I'd use an array of arrays instead: ...
    (comp.lang.perl.misc)
  • Re: Looping over arrays.
    ... > of an array is known the moment it is created. ... JVM it gets translated into a special JVM bytecode that retrieves the size of ... optimisation the JVM does -- for instance the JIT could ... but when it comes to production code the general ...
    (comp.lang.java.programmer)
  • Re: Bad code or bad compiler? THANKS
    ... Since the actual production code also uses realloc() to extend the array, ...
    (comp.lang.c)
  • Re: Dealing properly with scope; came from:combine array(string) to string?
    ... Unless you have a method that doesn't return an array (i.e. something ... other than map/collect). ... loop counter. ... For production code, I agree. ...
    (comp.lang.ruby)
  • Re: "init.c: No such file or directory."
    ... I ran the program with a debugging option (gdb) and I got the ... I've tried starting with a working version and building it up to the point where it fails, and my experience with that method hasn't been good. ... If it fails with array size 65536, ...
    (comp.lang.fortran)