aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Syntax clarification Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Syntax clarification" Watch "Syntax clarification" New topic

Syntax clarification

Ajit Sawant
Ranch Hand

Joined: Nov 26, 2008
Posts: 33
Partial code from SCJP 6 pg 586:

I did not understand "subset = (TreeSet)times.headSet(1600)" . What is "(TreeSet)times" trying to do? Please clarify.

Ruben Soto
Ranch Hand

Joined: Dec 16, 2008
Posts: 1032
The way that is evaluated is (TreeSet)(times.headSet(1600))
Here, times.headSet(1600) returns a SortedSet reference to a TreeSet, which means that the whole expression is a legal downcast.

All code in my posts, unless a source is explicitly mentioned, is my own.
I agree. Here's the link:
subject: Syntax clarification
Similar Threads
Collections-Getting error, using subList(fromIndex, toIndex) in List!
ClassCastException using Treemap.headMap()
Generics - Unchecked conversion warning
Subset doubt
What is the Use of NavigableMap and NavigableSet?