PDA

Click to See Complete Forum and Search --> : [Resolved] Can you identify and explain this syntax?


monotonehell
Dec 1st, 2009, 09:38 PM
Hello,

I normally develop in vb.net but for this one project I'm examining some decompiled java code to obtain hook-in points for another application I've been asked to write.

Most Java code I find I can follow as its syntax is fairly obvious, but this one line I don't understand the syntax...
JFrame localJFrame = (JFrame)localClientServices.getMainPane();
That is, I understand what it's achieving, but the bit that I don't understand is:
(JFrame)localClientServices.
I can't find any explanation in the Java tutorials as to what something in brackets before something else means, where you would use it, and what it can refer to.

Remember I'm interested in the syntax of this expression in general, and not the specifics of the example (I think it's something to do with interfaces and types?).

I've been reading Java tutorials all morning, any help and pointers will be appreciated.

monotonehell
Dec 1st, 2009, 10:44 PM
Ohhhhh! It's dynamic type casting.

Well there you go, I can't see the Sun tutorial mentions what it is at all before it uses it in examples. >.<'

David Anton
Dec 2nd, 2009, 02:01 AM
In VB, that would just be:
Dim localJFrame As JFrame = CType(localClientServices.getMainPane(), JFrame)

monotonehell
Dec 2nd, 2009, 03:17 AM
Thanks for confirming that David. It was bugging me.

Actually it's not far off c++ is it?
a = (int) b;

I find the lack of space disturbing. ;)
/blatant Star Wars reference.