Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 17 Mar 1998 20:24:44 -0500
From:      Randall Hopper <rhh@ct.picker.com>
To:        java@FreeBSD.ORG
Subject:   Reflection Test: Bug or Feature?
Message-ID:  <19980317202444.57262@ct.picker.com>

next in thread | raw e-mail | index | archive | help

--a8Wt8u1KmwUX3Y2C
Content-Type: text/plain; charset=us-ascii

     Running through the examples in Core Java 1.1 (Horstmann & Cornell)
with the FreeBSD JDK 1.1.5 port, V98-2-25 (thanks for the port guys!).

     There's this ReflectionTest.java program (Ch5, Ex5-4; pp. 187-8) that
uses reflect to print out a class definition for any class the JavaVM knows
about.  

     Running it on "java.lang.Double" prints respectable output that
matches the book (see Attachment 1), but running it on "java.util.Date"
produces (what appear to be) corrupt values for the last two class
constants:

     private static final long serialVersionUID;
     private static final [Ljava.lang.String; wtb;
     private static final [I ttb;
     }

(see Attachment 2 for full output)

Is this a bug, or something I just don't know yet.

Here's a shortened program that dumps the fields of "java.util.Date" so you
can see this:

     import java.lang.reflect.*;
     
     public class RefTest
     {  public static void main(String[] args)
        {  String  cl_name = "java.util.Date";
           Class   cl = null;
           try {
              cl = Class.forName( cl_name );
           }
           catch(ClassNotFoundException e)
           {  System.out.println( "Unknown class" );
              System.exit(1);
           }
     
           Field [] fields  = cl.getDeclaredFields();
     
           for ( int i = 0; i < fields.length; i++ )
           {  Field f     = fields[i];
              Class type  = f.getType();
              String name = f.getName();
              System.out.println( Modifier.toString( f.getModifiers() ) +
                                  " " + type.getName() + " " + name + ";" );
           }
        }
     }

Thanks,

Randall

--a8Wt8u1KmwUX3Y2C
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="OUT.java.lang.Double"

> java ReflectionTest
Please enter a class name (e.g. java.util.Date):  java.lang.Double

class java.lang.Double extends java.lang.Number
{
public java.lang.Double(double);
public java.lang.Double(java.lang.String);

public static java.lang.String toString(double);
public static java.lang.Double valueOf(java.lang.String);
public static boolean isNaN(double);
public static boolean isInfinite(double);
public boolean isNaN();
public boolean isInfinite();
public java.lang.String toString();
public byte byteValue();
public short shortValue();
public int intValue();
public long longValue();
public float floatValue();
public double doubleValue();
public int hashCode();
public boolean equals(java.lang.Object);
public static native long doubleToLongBits(double);
public static native double longBitsToDouble(long);
static native double valueOf0(java.lang.String);

public static final double POSITIVE_INFINITY;
public static final double NEGATIVE_INFINITY;
public static final double NaN;
public static final double MAX_VALUE;
public static final double MIN_VALUE;
public static final java.lang.Class TYPE;
private double value;
private static final long serialVersionUID;
}

--a8Wt8u1KmwUX3Y2C
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="OUT.java.util.Date"

> java ReflectionTest
Please enter a class name (e.g. java.util.Date):  java.util.Date
class java.util.Date
{
public java.util.Date();
public java.util.Date(long);
public java.util.Date(int, int, int);
public java.util.Date(int, int, int, int, int);
public java.util.Date(int, int, int, int, int, int);
public java.util.Date(java.lang.String);

public static long UTC(int, int, int, int, int, int);
public static long parse(java.lang.String);
public int getYear();
public void setYear(int);
public int getMonth();
public void setMonth(int);
public int getDate();
public void setDate(int);
public int getDay();
public int getHours();
public void setHours(int);
public int getMinutes();
public void setMinutes(int);
public int getSeconds();
public void setSeconds(int);
public long getTime();
public void setTime(long);
public boolean before(java.util.Date);
public boolean after(java.util.Date);
public boolean equals(java.lang.Object);
public int hashCode();
public java.lang.String toString();
public java.lang.String toLocaleString();
public java.lang.String toGMTString();
public int getTimezoneOffset();
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
private void checkCal();
private void checkModified();

private transient java.util.Calendar cal;
private transient long fastTime;
private transient boolean modified;
private static final long serialVersionUID;
private static final [Ljava.lang.String; wtb;
private static final [I ttb;
}

--a8Wt8u1KmwUX3Y2C--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-java" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19980317202444.57262>