• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Generic Ques

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the Difference between Refereing a Vector like Vector<?> or with Vector<Object>

For Example

import java.util.*;


class Test {

public static void main(String args[]) {

Vector<?> vec = new Vector<A>();

vec = new Vector<B>();
}
}

abstract class timepass{

}

class A extends timepass{

}

class B extends timepass {

}
 
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generics in the Java Programming Language Page 5. may help you.
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the case of ? any class could be in there. In the case of Object, only Objects of class Object can be placed in there, you cannot put in any subclasses. So that means you would have to downcast all your subclasses to type Object. Very simplified version, and you should study it more, but for simply determining what goes in the Vector<?> vs Vector<Object>

Mark
 
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys
As far as my idea i concern in case of Vector<?> we can replace ? with any thing i.e. Object or Interface
[/list]
But for Vector<Object> you can not pass Interface as type like
 
    Bookmark Topic Watch Topic
  • New Topic