Java Forum / General / April 2007
generics "erasure" doubt
josh - 24 Apr 2007 12:03 GMT Hi I've a doubt with generics erasure.
When the compiler do an "erasure" it always convert type parameters with Object type?
If I've a method in which I pass an Integer object the E typo is translated with Object or with Integers?
Lew - 24 Apr 2007 13:07 GMT > Hi I've a doubt with generics erasure. No, you don't. You have a question. A doubt is a suspicion, e.g., about veracity or honesty.
> When the compiler do an "erasure" it always convert type parameters > with Object type? No, it never does.
> If I've a method in which I pass an Integer object the E typo [sic] is > translated with Object or with Integers? Neither. "Erasure" means that the type parameter goes away entirely.
 Signature Lew
josh - 25 Apr 2007 09:28 GMT > > Hi I've a doubt with generics erasure. > [quoted text clipped - 5 lines] > > No, it never does. are you sure ? many books doesn't say that!
> > If I've a method in which I pass an Integer object the E typo [sic] is > > translated with Object or with Integers? > > Neither. "Erasure" means that the type parameter goes away entirely. are you sure ? I'm reading that!
Hendrik Maryns - 25 Apr 2007 11:00 GMT josh schreef:
>>> Hi I've a doubt with generics erasure. >> No, you don't. You have a question. A doubt is a suspicion, e.g., about [quoted text clipped - 11 lines] > > are you sure ? I'm reading that! My guess: you have to read better.
H.
- -- Hendrik Maryns http://tcl.sfs.uni-tuebingen.de/~hendrik/ ================== http://aouw.org Ask smart questions, get good answers: http://www.catb.org/~esr/faqs/smart-questions.html
Lew - 25 Apr 2007 12:49 GMT josh schreef:
>>> When the compiler do an "erasure" it always convert type parameters >>> with Object type? Lew wrote:
>> No, it never does. josh schreef:
> are you sure ? Yes.
josh schreef:
> many books doesn't say that! Which books? What /do/ they say?
josh schreef:
>>> If I've a method in which I pass an Integer object the E typo [sic] is >>> translated with Object or with Integers? Lew wrote:
>> Neither. "Erasure" means that the type parameter goes away entirely. josh schreef:
> are you sure ? Yes. Why else would I risk putting it out here in a public place where everyone can see it? Don't worry, I will let you know if I am unsure, otherwise do not doubt it. (Now you are expressing doubt, by the way. See the differeence? You suspect my answer, so you doubt it. It's still correct, of course, despite your doubts.)
josh schreef:
> I'm reading that! You're reading what. specifically?
As the name indicates, type erasure erases the type parameter. It doesn't convert it.
Hint: What is the dictionary definition (in English) of the word "erasure"? <http://en.wiktionary.org/wiki/erasure> <http://en.wiktionary.org/wiki/erase>
Reference: <http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.6>
 Signature Lew
Ingo R. Homann - 26 Apr 2007 07:44 GMT Hi josh,
apart from the meaning of the word "doubt" (I am no native speaker ;-), I think you are right, in what type erasure does. Consider having a class like this:
class Container<T> { T t; void set(T t) { this.t=t; } }
Then it is true - AFAIK - that T (in line 1) is "erased" whereas the other T's can be thought of "replaced by Object". (Of course, type erasure does a bit more because there are no casts necessary, which would be the case if you replaced T to Object manually.)
Ciao, Ingo
josh - 26 Apr 2007 07:53 GMT > josh schreef: > [quoted text clipped - 50 lines] > -- > Lew ok, I post this form Java How To Program 6Ed and so you can understand me why I have some "doubts" and not some questions!
this is from Chapter 18 the listing // generic method printArray public static < E > void printArray( E[] inputArray ) { // display array elements for ( E element : inputArray ) System.out.printf( "%s ", element ); System.out.println(); } // end method printArray
and this is the phrase:
>>> When the compiler translates generic method printArray into Java bytecodes, it removes the type parameter section and replaces the type parameters with actual types. This process is known as erasure. By default all generic types are replaced with type Object <<<
so it is said "removes" and than "replaced" and than look at that final book example:
public static void printArray( Object[] inputArray ) { // display array elements for ( Object element : inputArray ) System.out.printf( "%s ", element ); System.out.println(); } // end method printArray
Regards
Esmond Pitt - 26 Apr 2007 08:07 GMT > ok, I post this form Java How To Program 6Ed> > ... [quoted text clipped - 5 lines] > This process is known as erasure. > By default all generic types are replaced with type Object <<< So what does it say about translating generic *classes* into Java. Don't tell me it says that GenericClass<T> is translated into GenericClass<Object>. Which is where we came in.
> so it is said "removes" and than "replaced" and than look at that > final book example: That example being about a generic method not a generic class is consistent with what you've been told here.
John W. Kennedy - 26 Apr 2007 04:04 GMT >> Hi I've a doubt with generics erasure. > > No, you don't. Yes he does. If you're going to correct someone's language, be sure you know what you're talking about, first.
> A doubt is a suspicion, e.g., about veracity or honesty. You're wrong.
 Signature John W. Kennedy "Compact is becoming contract, Man only earns and pays." -- Charles Williams. "Bors to Elayne: On the King's Coins" * TagZilla 0.066 * http://tagzilla.mozdev.org
Lew - 26 Apr 2007 12:34 GMT >>> Hi I've a doubt with generics erasure. >> [quoted text clipped - 6 lines] > > You're wrong. No, you're wrong, genius. <http://en.wiktionary.org/wiki/doubt>
> Verb > [quoted text clipped - 24 lines] > > [edit]
 Signature Lew
Larry Barowski - 26 Apr 2007 14:23 GMT >>>> Hi I've a doubt with generics erasure. >>> [quoted text clipped - 8 lines] > > No, you're wrong, genius. This same topic was discussed here a few weeks ago. In British and American English, the nouns "doubt" and "question" are never synonymous, but it seems that in Indian English they can be. "josh" sounds like an American name, but you never know.
John W. Kennedy - 26 Apr 2007 17:37 GMT >>>> Hi I've a doubt with generics erasure. >>> [quoted text clipped - 36 lines] >> >> He doubted that was really what you meant. To begin with, you might want to look up the noun, rather than the verb, since it is the noun that is under discussion. But that's neither here nor there, really, seeing that Wiktionary is far less reliable than Wikipedia to begin with. (A competent encyclopedia article requires the author merely to be knowledgeable on the subject at hand, and literate; a competent dictionary entry requires the author to be a lexicographer.)
doubt –noun 5. a feeling of uncertainty about the truth, reality, or nature of something. 6. distrust. 7. a state of affairs such as to occasion uncertainty. 8. Obsolete. fear; dread.
-- Dictionary.com. Dictionary.com Unabridged (v 1.1). Random House, Inc. http://dictionary.reference.com/browse/doubt (accessed: April 26, 2007).
doubt n. 1. A lack of certainty that often leads to irresolution. See Synonyms at uncertainty. 2. A lack of trust. 3. A point about which one is uncertain or skeptical: reassured me by answering my doubts. 4. The condition of being unsettled or unresolved: an outcome still in doubt.
-- Dictionary.com. The American Heritage® Dictionary of the English Language, Fourth Edition. Houghton Mifflin Company, 2004. http://dictionary.reference.com/browse/doubt (accessed: April 26, 2007).
doubt noun 1. the state of being unsure of something [ant: certainty] 2. uncertainty about the truth or factuality or existence of something; "the dubiousness of his claim"; "there is no question about the validity of the enterprise"
-- Dictionary.com. WordNet® 3.0. Princeton University. http://dictionary.reference.com/browse/doubt (accessed: April 26, 2007).
 Signature John W. Kennedy "Those in the seat of power oft forget their failings and seek only the obeisance of others! Thus is bad government born! Hold in your heart that you and the people are one, human beings all, and good government shall arise of its own accord! Such is the path of virtue!" -- Kazuo Koike. "Lone Wolf and Cub: Thirteen Strings" (tr. Dana Lewis) * TagZilla 0.066 * http://tagzilla.mozdev.org
Larry Barowski - 27 Apr 2007 13:30 GMT > Definitions of "doubt" None of those definitions are "a interrogative statement" or "a request for information", which is how the OP used the word "doubt". In American and British English, it never has that meaning.
John W. Kennedy - 27 Apr 2007 20:26 GMT >> Definitions of "doubt" > > None of those definitions are "a interrogative statement" or > "a request for information", which is how the OP used the > word "doubt". In American and British English, it never > has that meaning. "a feeling of uncertainty about the truth, reality, or nature of something"
"A lack of certainty that often leads to irresolution. See Synonyms at uncertainty."
"the state of being unsure of something [ant: certainty]"
The "interrogative statement" and "request for information" exist only in your interpretation.
 Signature John W. Kennedy Read the remains of Shakespeare's lost play, now annotated! http://pws.prserv.net/jwkennedy/Double%20Falshood/index.html * TagZilla 0.066 * http://tagzilla.mozdev.org
Larry Barowski - 28 Apr 2007 00:52 GMT > The "interrogative statement" and "request for information" exist only in > your interpretation. Read the OP again. How else would you interpret "I've a doubt with generics erasure"? He doesn't seem to doubt that generics erasure exists, and doesn't go on to discuss any sort of doubt related to erasure. He does have some questions about how erasure works. The two statements that follow seem to be requests for information, and not requests to confirm or deny suspicions. Try this: "I have some doubts about ferrets. Are they in the weasel family? How many toes do they have?". "doubts" could be the correct word there for the intended meaning, but it would be a strange sequence of sentences.
John W. Kennedy - 28 Apr 2007 03:21 GMT >> The "interrogative statement" and "request for information" exist only in >> your interpretation. [quoted text clipped - 5 lines] > erasure works. The two statements that follow seem to be requests > for information, and not requests to confirm or deny suspicions. You keep insisting that "doubt" == "suspicion".
> Try this: "I have some doubts about ferrets. Are they in the weasel > family? How many toes do they have?". "doubts" could be the > correct word there for the intended meaning, but it would be a > strange sequence of sentences. Oh God! We mustn't have people making sentences the way YOU wouldn't. I mean, next thing, they'll be trying to marry each other....
 Signature John W. Kennedy "...if you had to fall in love with someone who was evil, I can see why it was her." -- "Alias" * TagZilla 0.066 * http://tagzilla.mozdev.org
Larry Barowski - 28 Apr 2007 16:34 GMT >>> The "interrogative statement" and "request for information" exist only >>> in your interpretation. [quoted text clipped - 7 lines] > > You keep insisting that "doubt" == "suspicion". I've never insisted on that, or even hinted at it. The paragraph above is the first in which I've even used the word.
He doesn't go on to discuss any sort of doubt related to erasure, using any definition of "doubt" that you supplied earlier. He does follow with two very direct questions.
>> Try this: "I have some doubts about ferrets. Are they in the weasel >> family? How many toes do they have?". "doubts" could be the [quoted text clipped - 3 lines] > Oh God! We mustn't have people making sentences the way YOU wouldn't. I > mean, next thing, they'll be trying to marry each other.... Your point seems to be that we should assume that disjointed sentences in sequence are just as likely as related ones. I think you'll find that related sentences occur much more frequently, even when they are written by people other than ME.
John W. Kennedy - 29 Apr 2007 03:46 GMT >>>> The "interrogative statement" and "request for information" exist only >>>> in your interpretation. [quoted text clipped - 24 lines] > you'll find that related sentences occur much more frequently, > even when they are written by people other than ME. They are related. He states that he is not clear on how type erasure works with Java generics. Then he asks some questions that he hopes will clarify his understanding. His sentences are somewhat parataxic, but hardly disjointed.
 Signature John W. Kennedy "Those in the seat of power oft forget their failings and seek only the obeisance of others! Thus is bad government born! Hold in your heart that you and the people are one, human beings all, and good government shall arise of its own accord! Such is the path of virtue!" -- Kazuo Koike. "Lone Wolf and Cub: Thirteen Strings" (tr. Dana Lewis) * TagZilla 0.066 * http://tagzilla.mozdev.org
JT - 30 Apr 2007 18:09 GMT > Read the OP again. How else would you interpret "I've a doubt > with generics erasure"? He doesn't seem to doubt that generics > erasure exists, and doesn't go on to discuss any sort of doubt > related to erasure. He does have some questions about how > erasure works. The two statements that follow seem to be requests > for information, and not requests to confirm or deny suspicions. May I just interject here:
In India, the word "doubt" means the same as "question". Maybe it's because "doubt" is easier to pronounce. But people would say things like:
* Can I ask a doubt about Linux?
* Students, go home and finish the 10 doubts in chapter 1.
* Okay, students. Any more doubts before we end the class?
In England, they don't say "cell phone" or "tv", they say "mobile" and "telly".
In India, they don't say "question"; they say "doubt".
The OP's name sounds western, but he very well could be born and raised in India by his western parents.
- JT
Joshua Cranmer - 28 Apr 2007 21:53 GMT > "a feeling of uncertainty about the truth, reality, or nature of something" > [quoted text clipped - 5 lines] > The "interrogative statement" and "request for information" exist only > in your interpretation. Those statements do not the match the OP's original statement. All of them in essence mean that a doubt requires a presumption of truth. The OP's original statements neither presume that the answer is "yes" or "no"; thus, they do not have the fundamental questioning of truth that is necessary for doubt to exist.
John W. Kennedy - 29 Apr 2007 03:41 GMT >> "a feeling of uncertainty about the truth, reality, or nature of >> something" [quoted text clipped - 9 lines] > Those statements do not the match the OP's original statement. All of > them in essence mean that a doubt requires a presumption of truth. "Is this a statement that I see before me?" -- Lewis Carroll: "A Tangled Tale"
 Signature John W. Kennedy "I want everybody to be smart. As smart as they can be. A world of ignorant people is too dangerous to live in." -- Garson Kanin. "Born Yesterday" * TagZilla 0.066 * http://tagzilla.mozdev.org
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|