File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Generic Ques Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Generic Ques" Watch "Generic Ques" New topic
Author

Generic Ques

Mohammed Yousuff
Ranch Hand

Joined: Apr 18, 2006
Posts: 45
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 {

}


Regards<br /> <br />Mohammed Yousuff M N <br /> <br />Try NOT to Become a man of SUCCESS, BUT Try to Become a man of VALUE..
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
Generics in the Java Programming Language Page 5. may help you.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Amirr Rafique
Ranch Hand

Joined: Nov 14, 2005
Posts: 324
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


"Know where to find the solution and how to use it - that's the secret of success."
 
Don't get me started about those stupid light bulbs.
 
subject: Generic Ques
 
Similar Threads
n-dimensioned array in Java
Why is this an unchecked cast?
Change & sort the contents of JComboBox in Swing
problem in chatting program
chat program