• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Vector Question!!

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you subclass a vector can you put primitives in it? (I know vectors only hold objects)Can you even subclass a Vector?
public class Subvector extends Vector
int i=5; //does error occur here?
public static void main(String args[ ])
Subvector sv = new Subvector( ) //does error occur here?
System.out.println(sv.i) //does error occur here?
Thanks in Advance
Best Regards
Edmund
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Didn't we go through this exact question just a short while ago?
The answer is no. All your example did was add a single int to a Vector object. The Vector would still not be able to hold more than one int. You could create a whole new class call IntCollection based on the Collection interface that does hold ints in an array.
As far as your questions about when an error occurs, you can download the Java J2SE from Sun and try it yourself.
[This message has been edited by Thomas Paul (edited April 26, 2001).]
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
if your criteria is only to put integers in vector class then use wrapper class in which you can give primitive values accordingly. later on you can conver object to primitive or primitive to objects accordingly.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic