Karl Prenton

Ranch Hand
+ Follow
since Mar 10, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Karl Prenton

Can anyone confirm what appears to be a 10% increase from the the 1st of September e.g. SCJP is now �165+vat (was �150)
thanks all for pointing that out
thanks...
Does that mean that I would not have to retake the essay exam (CX-310-027) ?

or

should the written exam only be taken in the event of a successful assignment?

I guess the latter doesn't make sense because it could be a while before the assignment result is given I understand.
It would be nice if there was more info on the Sun website regarding assignments procedure (scjd/scea).
Is it possible to fail the assignment but pass the written exam?
If so, do I need to re-take the written exam?

tia
That book is a bit out of date. Since java 1.5, option e would also be correct - see covariant return types.
I guess the code was a little misleading; probably the type of code to find in an exam!

obviously, code compiles for the more general case:
public void addAnother(List<? super Object> l)

which is equivalent as non-generic :
public void addAnother(List l)

Originally posted by Keith Nagle:
At compile time, you cannot add to a collection that has
<? extends ...> for the simple reason that you could be adding something that could upset your collection.
Just remember that if you want to add something to a collection, the following are legitimate:


Best regards.

[ July 11, 2008: Message edited by: Keith Nagle ]



I quickly tried this out and compiler was complaining:
$ javac GenericsPractice.java
GenericsPractice.java:25: cannot find symbol
symbol : method add(Animal)
location: interface java.util.List<capture of ? super Dog>
l.add(new Animal());
^
GenericsPractice.java:26: cannot find symbol
symbol : method add(java.lang.Object)
location: interface java.util.List<capture of ? super Dog>
l.add(new Object());
^
2 errors


I don't understand why? The code made perfect sense to me!
Any else have this bizarre problem??
It's as if the compiler cannot see "? super" ... this has got me worried now!
I'm using jdk 1.5.0_10
[ July 11, 2008: Message edited by: Frank Zito ]
your right about not using eclipse for scjp work. I find netbeans ok though for non-classpath related work.
@jagan - you havn't stated what version of jre/eclipse your using, also check your jdk compiler compliance level

eclipse 3.3.1.1 & jdk 1.6.0_05 seems consistent in this situation
[ July 06, 2008: Message edited by: Frank Zito ]
I get an compiler error - but only in eclipse ide (v3.3.2).
I think this is an example of why we seriously shouldn't use the eclipse ide! It uses it's own compiler - which appears to have a bug wrt varargs?!? @mods please confirm this?

just look at all the compiler bugs in the release notes...
http://www.eclipse.org/eclipse/development/readme_eclipse_3.3.2.html


eclipse compiler (JDT/ECJ) also gives slightly different warning/error messages.

Using cli or netbeans it seems to compile fine.
[ June 24, 2008: Message edited by: Frank Zito ]
exam tip: remember that java/javac will also look in <installed java>/jre/lib/ext for any jars without explicitly naming that directory in the classpath

"java -cp A\A1 Test" should NOT work!

The class file will be in the same directory as the source. Use package notation :
"java A.A1.Test"

use classpath when running from a directory other that the package "root" (K&B might help u) e.g.
"java ..\.. A.A1.Test" when running in c:\ls10\A\A1


javac just works with files, the target must have a path if your working directory is somewhere else (you class doesn't need a classpath) :
"javac A\A1\Test.java" (on windows)
Java will print out the stack trace for any uncaught exception, on the current thread.
Since the exception was deliberately thrown on a different thread, the printed stack trace can occur before or after "main" gets printed.
[ June 18, 2008: Message edited by: Frank Zito ]
The wildcard return type doesn't tally with the specific type (Integer/Number). It may help to visualize the code without generics in each case aka erasure.

The code compiles if output is declared with the same range :
List<? super Integer> output = null;

The same applies when using an upper bound wildcard instantiation : <? extends E>

HTH