Tomasz Sochanski

Ranch Hand
+ Follow
since Jan 13, 2009
Tomasz likes ...
Eclipse IDE Java Oracle
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
12
Received in last 30 days
0
Total given
9
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Tomasz Sochanski

Chandra shekar M wrote:



This is really interesting, it seems that declaring list as List<String> will cause method getInstance(int) to create ArrayList for String objects, and declaring it as List<BigDecimal> will do this list for BigDecimals (in runtime both of them are just Lists of Objects with proper casting added to methods operating on those elements). Anybody could clarify what happens here?

Dattaprasad Bhangle wrote:
but method local inner classes will not vanish like all other local variables when method execution completes...


I am not sure what you mean. There is still possibility to refer object of such class outside method body like this:



Here object reference points to Local class instance. However object reference cannot be declared as Local type. In this example it has to be declared as Object, in other situations it could be any supertype of such local class. When reference type is declared in line 3 java.lang.Object class modifier (public) is used . When object instance is created in line 18 no modifiers are needed. This is the only place in this code snippet where Local class can be instantiated and the only place, where potentially access modifiers could allow or disallow object creation / refering.
I believe you ask why they cannot be public, private or protected. You can read here :

A local class is a nested class (§8) that is not a member of any class and that has a name. (...) The scope of a local class declared in a block is the rest of the immediately enclosing block, including its own class declaration. (...) It is a compile-time error if a local class declaration contains any one of the following access modifiers: public, protected, private, or static.


Class declared in method is accessible (can be instantiated, its methods can be run etc) only from declaring method body block (after class declaration). This is the same situation as is with method local variables. There is no sense to add modifier like public or private to it becase it is always accessible in any fragment of the code inside declaring block (after clas declaration) and never accessible outside of this block.
my bet is:

Thanks Joanne for your notice regarding unnecessary call to bf.close().
PrintWriter is closed when you call BufferedWriter.flush(), first run bf.flush(), then pw.close().
I would do the same exactly. Before being certified as OCPJP7 you have to pass either OCPJP or OCJA. Choose which one is more valuable for you.
That is right, I didnt notice that.

O. Ziggy wrote:
I thought the compiler warnings will only appear if you mix generic code with non-generic code.


SubArrayList schould be defined this way to avoid warnings:

Hi Ganesan,

Henry Wong announcing you here on this forum called the product 'software'. Provided link to promotion page on JavaRanch is named 'Book Promotion Page'. Here on Epractize Labs page it is called 'software book'. Could you please clarify what is it exactly, what is inside this blue box? And if it is a software what are requirements to run it (operating system / jvm ? any other specific?).

Regards
T.
it is expected to be released in summer 2013, take a look here.

Dorothy Taylor wrote:So if we need to sort these Person objects based on the natural ordering of each person’s complete name, then is it ok to just extend Comparator interface and implement the compare() method?



Dorothy,

You cannot extend interface in class, you can implement it. If you tried your idea (which I strongly suggest) then you already noticed it won't work. Not every Map implementation cares about key ordering, you have to choose the one which does (ie. TreeMap).

TreeMap javadoc stands:


The map is sorted according to the natural ordering of its keys, or by a Comparator provided at map creation time, depending on which constructor is used.


So you can either implement Comparable (not Comparator) interface in Person class, or create implementation of Comparator and provide it during initialization of map. You would also want to read about Collator if you have to care about national characters in names, like 'é', 'ą', 'ö' etc.