Re: Are primitives objects?

From: Igor L (patak_dacha_at_yahoo.com.hk)
Date: 01/09/04

  • Next message: Bjoern Eberth: "java and ldap"
    Date: Fri, 9 Jan 2004 09:13:25 +0100
    
    

    No, primitives are not objects. Yet, if you need an object (for example to
    put it in a hashtable or something) you can do the following:

    int i = 3;
    Integer object_i = new Integer(i);

    now you have an object and you can do

    System.out.println(object_i.getClass());

    Every primitive type has it's own corresponding object type.
    int -> Integer, double -> Double, etc.

    See documentation on this classes.

    "Fred" <Fred@isp.com> wrote in message news:OssLb.3817$na.5853@attbi_s04...
    > Are primitives objects?
    >
    > int i = 3;
    > System.out.println(i.getClass());
    >
    > doesn't compile. Get an error message
    > "int can't be dereferenced"
    >
    > But yet the docs for class Object say:
    > Class Object is the root of the class hierarchy. Every class has Object
    as
    > a superclass.
    >
    >
    >


  • Next message: Bjoern Eberth: "java and ldap"

    Relevant Pages

    • Re: Are primitives objects?
      ... int i = 3; ... >> Wrapper classes are indeed handy for the primitives. ... >> array class, primitive type, or void) represented by this Class object, ...
      (comp.lang.java)
    • Re: Java Indexing- Historical question
      ... And when the array is of primitives there should be a dramatic benefit in memory usage as well. ... RestrictedRangeIntegerKeyedMapif you prefer) implements Mapthat only accepted keys in a given range, and stored its elements in an array. ... public ArrayMap(int base, int size) { ...
      (comp.lang.java.programmer)
    • Re: A Brief Look at History
      ... design graphics packages to draw a box you sure picked a loser for a ... Then why didn't Brodie use the more convenient primitives you suggested? ... I maintain that BOX2 is going to be far more effective ... void box2 (int l, int t, int r, int b) ...
      (comp.lang.forth)
    • Re: Java ready for number crunching?
      ... I don't like boxing and unboxing primitives as there is a space and speed penality (or is there? ... Please let Sun, IBM, NIST, the academy, or any authors of java numerical software know of your insight. ... int = int ...
      (comp.lang.java.programmer)
    • Re: Loading classes with primitive types in constructor
      ... > have a constructor that takes an int as a parameter. ... You use wrapper classes for primitive types. ... primitives, but also whenever you want to pass an object where the ... constructor is declared with a supertype for the parameter. ...
      (comp.lang.java.programmer)