wood burning stoves 2.0*
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
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.
subject: Syntax clarification
Similar Threads
What is the Use of NavigableMap and NavigableSet?
Collections-Getting error, using subList(fromIndex, toIndex) in List!
Generics - Unchecked conversion warning
Subset doubt
ClassCastException using Treemap.headMap()