File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Generic Ques" Watch "Generic Ques" New topic

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

Joined: Feb 05, 2001
Posts: 17276

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>


Perfect World Programming, LLC - iOS Apps
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
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."
I agree. Here's the link:
subject: Generic Ques
It's not a secret anymore!