redho home | products | services
Web Design Forums

Web Design Forums  


Web Hosting, Web Design, Software and Web Development Forums  
 FAQFAQ   MemberlistArchive  Log inLog in   RegisterRegister 
         

adding generics


Goto page Previous  1, 2
 
Post new topic   Reply to topic    Web Design Forums -> JAVA programming forum
View previous topic :: View next topic  
Author Message
Gladis



Joined: 24 May 2006
Posts: 108
Std is the standard namespace... C++ has templates.
  Reply with quote


amoralis



Joined: 22 Jun 2006
Posts: 21
In java it only represents compile time checking
  Reply with quote
Gladis



Joined: 24 May 2006
Posts: 108
amoralis, It SHOULD affect code. Compile time checking leads to a few problems.
For instance... can't create genericized lists.
  Reply with quote
AmeliaR



Joined: 31 May 2006
Posts: 142
The difference is that c++ template generate code. java's generics do not.
  Reply with quote
amoralis



Joined: 22 Jun 2006
Posts: 21
That's what I just said :)
  Reply with quote
Gladis



Joined: 24 May 2006
Posts: 108
But C++ is faster with worse code. So.
  Reply with quote
Aaron Zapashniy



Joined: 04 Jun 2006
Posts: 17
Location: Hungary
Now i read something about variance.. and what i briefly read gave me the impression that i'd be able to specify my method as void doIt(List<Parent..>) or void doIt(List<-Parent>)
  Reply with quote
amoralis



Joined: 22 Jun 2006
Posts: 21
This issue Aaron Zapashniy raised is obnoxious because you can't overload methods with the only different in parameters being the object parameterizing the generic collection
I.e. doIt(List<parent> list); can't be overriden by doIt(List<Child> list);
  Reply with quote
Gladis



Joined: 24 May 2006
Posts: 108
Aaron Zapashniy, List<? extends Parent>
Which includes Parent and all subclasses of parent.
  Reply with quote
Aaron Zapashniy



Joined: 04 Jun 2006
Posts: 17
Location: Hungary
OOooh
That's nice!
  Reply with quote
Gladis



Joined: 24 May 2006
Posts: 108
Or the completly useless <? super Parent>, which is the superclass and all subclasses of superclasses of Parent.
  Reply with quote


Aaron Zapashniy



Joined: 04 Jun 2006
Posts: 17
Location: Hungary
Gladis, <Object> Wink
  Reply with quote
amoralis



Joined: 22 Jun 2006
Posts: 21
<- still can't use generics on a regular basis
  Reply with quote
martinar_kauaro



Joined: 18 Jun 2006
Posts: 4
? extends Foo is bad, it's not better than no generics.
  Reply with quote
Gladis



Joined: 24 May 2006
Posts: 108
Aaron Zapashniy, Ah, but it's more typing and harder to read!
It must be better!
  Reply with quote
amoralis



Joined: 22 Jun 2006
Posts: 21
martinar_kauaro, why is it bad?
  Reply with quote
Gladis



Joined: 24 May 2006
Posts: 108
martinar_kauaro, It does what we want it to do. how is that bad?
  Reply with quote
Aaron Zapashniy



Joined: 04 Jun 2006
Posts: 17
Location: Hungary
I'd think it'd basically just say "hey compiler, make sure whatever i throw at this method contains Parents in one form or another"
  Reply with quote
martinar_kauaro



Joined: 18 Jun 2006
Posts: 4
amoralis, Because you're again killing the typesafety. I've seen quite some code snippets that relied on generics to find "wrong object type inserted" exceptions.
  Reply with quote
amoralis



Joined: 22 Jun 2006
Posts: 21
martinar_kauaro, no you're not
you should be able to pass in a child class
  Reply with quote
Aaron Zapashniy



Joined: 04 Jun 2006
Posts: 17
Location: Hungary
If the method in question operates on the param as Parent, what harm could there be?
It'd provide exactly the level of type safety i desire.
(but WOW is that ugly and verbose syntax..)
  Reply with quote


Gladis



Joined: 24 May 2006
Posts: 108
Aaron Zapashniy, Well, Java as a whole is ugly and verbose syntax.
  Reply with quote
Aaron Zapashniy



Joined: 04 Jun 2006
Posts: 17
Location: Hungary
Ah well. i guess i'll just declare my collections with <Parent>.
Thanks fellas. Wink
  Reply with quote
Page 2 of 2 Goto page Previous  1, 2
Post new topic   Reply to topic    Web Design Forums -> JAVA programming forum


Dubai Forums - Expat Help | Vegan Chat | Java Programming | Free 3D tutorials and 3d textures | Paris Forum | EU Forum
Free Dubai Classifieds | Free London Classifieds | Jobs in London

High Quality, Custom 3d animation and Web Design solutions Royal Quality Web Hosting Services Vegetarian and Animal Rights news

Powered by phpBB © 2001, 2005 phpBB Group