Prasanta Chinara

Ranch Hand
+ Follow
since Jul 20, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Prasanta Chinara

CONGRATULATIONS!

Remember to take time off from your regular schedules and .. yes, CELEBRATE :-)
19 years ago
'glad to share with you my success in SCJP Tiger (78%).

It was quite a bit of hard word. I would like to thank the forum for a lot of inspiration and help (in the stimulating discussions).

For all those who are planning on 1.4, you can try for Tiger. Its fun!! I am a C++ programmer and my accidental encounter with a Generics tutorial article triggered the idea of SCJP. If I can make it, sure you can !
good luck

Following are a few SCJP Tiger prep material:

0. http://www.whizlabs.com/articles/scjp5.0-article.html (Java 5.0 Difference)
1. http://www.langer.camelot.de/Welcome.html (GENERICS)
2. http://java.sun.com/j2se/1.5.0/docs/relnotes/features.html (All Java Tiger new features.)
3. http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf (GENERICS)
4. http://java.sun.com/developer/JDCTechTips/ (Tech Tips - please select the relevant ones)
5. http://java.sun.com/docs/books/tutorial/ (Java tutorial - please select the relevant ones)

Books:
1. Java 2 Volume 5 Tiger New Features by Herbert Schildt

Online mock exams:
1. Latest Java 5.0 mock set by Marcus Green.

thanks,
Prasanta.
19 years ago
Thanks Ernest for point that out!
Thanks all for taking time to reply to my query.
Thanks Joseph.
That was my initial guess (after being pointed out by Marcus Green). But should not the compiler see that theres no such class hierarchy exists that can make it possible?

Well the outcome is: You can cast any class to any interface!


Even though "Unrelated" interface is no where in the hierarchy, still the code compiles fine. It will ofcourse error with ClassCastException at run time; But why does it compile? Where is the static type check the way it gets done for classes?

'appreciate any help.
An upper or lower bound in a generic method is declared as:

S super LowerBoundClass
or
S extends UpperBoundClass
No idea how that smily came in between ..
I meant:

((List<Reptile> li ) . add(new Reptile());
Well,

public <Reptile, S extends Reptile> void listContent(List<Reptile> myList, List<S> myOtherList)

Here the Reptile has nothing to do with your Reptile class!! The above declaration is just similar to:

public <R, S extends R> void listContent(List<R> myList, List<S> myOtherList)

So, here R and S are just 2 type parameters. Now considering erasure (or even without that), these 2 parameters could be anything say Integer, String or say ClassXYZ, ClassABC or whatever based on the where we are making the generic function call.

The walk() methos is only available to Reptile and its subclasses - by specifying:

public <R extends Reptile, S extends R> void listContent(List<R> myList, List<S> myOtherList)

we just say that.

----------------
"Towards 1.5 exam on Aug 4th"
Please post the complete code always!

I hope you have the following code (where Reptile is a concrete class):



Here, the static type of the variable li is List<?>. You CAN NOT add anything to a "list of ?" because "?" indicates, we don't know what type it is.

Now the below code would work:


The reasoning is as below:

The below code works! I am not sure if thats what you intended. I think, the error was in the definition of the generic method.



Hope that helps.
Could you please post the complete code.

The definition:
public <Reptile, S extends Reptile> void listContent(List<Reptile> myList, List<S> myOtherList)

looks like its intended to be a generic method - how do you mention concrete classes? Again, I am guessing Reptile is a concrete class.

Please post the complete code that can be compiled.
Does anyone share the same opinion that the Java language library is over crowded?

NO offense intended to the designers or any Java lovers; I feel highly overwhelmed to remember everything for real life use or for the SCJP exam.

--------------------------------
Ex1:
class String (methods):
1. int indexOf(int ch)
2. int indexOf(int ch, int fromIndex)
Method(1) can be easily acheived by int indexOf(int ch, 0) ;
--------------------------------
Ex2:
class File (static fields):
1. static String pathSeparator
2. static char pathSeparatorChar
One would be sufficient.
--------------------------------

C, as a language for example so elegantly handles the API.

'appreciate any thoughts.
Don't you think its little weired that even before the object is constructed, the polymorphism comes to play ?

The object is still being constructed .. how could the vtable (standard implementation for overriding function) be constructed properly?
Theres a nice book by Herb Sutter on new features for Java 5.0. Its an excellent book.

Following is a link on Generics:
http://www.langer.camelot.de/GenericsFAQ/JavaGenericsFAQ.html
An inner class (non static) instance always has an associated instance of an outer class.

Setting a class variable to null - does not change anything for the instance! If another variable (in this case the inner class) holds a reference (here indirectly) to the class instance, the instance exists. It stays and is not even eligible for garbage collection.

Hope that helps.