Henrique Sousa<br />SCJP 1.4<br /> <br />All men die, not all men really live - Braveheart, 1995
Originally posted by Guadalupe Ortiz:
I want to get exactly what type an Object is (for example, a String), to use the that type for casting the object itself.
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Why? Why on earth would you want to insert an unnecessary cast that the compiler is probably going to optimise away anyway? - PeterOriginally posted by Guadalupe Ortiz:
I can create a SealedObject from any Object, but it must be casted first, so I should something like:
SealedObject so = new SealedObject((String)obj, ecipher); (if I knew it were a String)
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Yes, well, that's absolutely correct, isn't it? I don't mean to offend you, but have you carefully read the documentation or any of our responses to your question? If you'd just look in the javadoc for SealedObject, in particular the constructors, or simply use the code I gave you above as given, all shall become clearOriginally posted by Guadalupe Ortiz:
"The constructor SealedObject(Object, Cipher) is undefined"
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
On the language level, the reference is being cast. On the JVM level, of course, it's the runtime type of the actual object that's relevant. The JVM spec requires a runtime check of the object type (checkcast), and the bytecode verification stage means that the compiler has to put that check in. The specification doesn't seem to mandate anything specific on the representation of references. You might also be interested in the description of the checkcast operation.Originally posted by marc weber:
I read somewhere that it's the reference that's actually being cast or converted, but I'm not convinced this is accurate.
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
Originally posted by marc weber:
I read somewhere that it's the reference that's actually being cast or converted, but I'm not convinced this is accurate. The reference is essentially just the object's memory address (or an address of that address, if "double-indirection" is used). The object's true type information is stored with the object, but I don't see that the reference itself contains any such information. Does it?
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Ilja Preuss:
Not at runtime. At compile time, though, you could see a reference as a tuple of (<memory for an objects address>, <allowed type of objects>
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Originally posted by marc weber:
In other words, reference type is the compiler's own bookkeeping, rather than anything inherent to the reference itself.
Originally posted by marc weber:
My impression -- and it's little more than that -- is that reference type is an "association" maintained at the language level by the compiler. I imagine the compiler putting a virtual Post-It on the reference, saying something like, "Note to self: This reference is to a String Object." In other words, reference type is the compiler's own bookkeeping, rather than anything inherent to the reference itself.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Yes, and yes, as far as my meager understanding is correct. See the JVM spec bits I linked to above.Originally posted by Ilja Preuss:
As I think about it, the type must also be present in the byte code, else compiling against binary libraries wouldn't be fully typesafe (say, if you access a puplic field). I'd guess it's also checked by the verifier at class loading time.
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
Get off me! Here, read this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|