(Answer) (Category) FAQ-O-Matic : (Category) General : (Category) Compiler : (Category) Javac VS JBuilder's bcj :
super.getSuperclass() and getClass.getSuperclass() return different results! Code compiled with javac returns the same value, but code compiled with JBuilder does not!
JB5 also produces two different outputs, but I believe it's javac in error, not JBuilder. But, I'm not a JLS lawyer, so I used an experiment to test it.

super.method() is having your object run the superclass's method() body. It's still your object running the method, not the parent class. this.getClass.method() is calling the method on the Class object corresponding to the superclass. This may not be what you intended. That object is of type Class, not the type of 'this'.

Here are two source files which illustrate the problem you're having more clearly. Run this and look at the output closely. Note that I had to comment part of Untitled2 to make it compile. You've been fooled because the method you're calling happens to exist all the way up the inheritance chain, but in my example below it does not.

  package xperiment1;
  public class Untitled1 {
    public Untitled1() {
     System.out.println("1 " + this.getClass() + " with parent " + super.getClass());
     System.out.println("1 " + this.getClass() + " with parent " + this.getClass().getSuperclass());
    }
    public static void main(String[] args) {
      Untitled1 untitled11 = new Untitled1();
    }
    public String getFoo() {
      return "untitled1 foo";
    }
  }
  
  package xperiment1;
  public class Untitled2 extends Untitled1 {
    public Untitled2() {
     System.out.println("2 " + this.getClass() + " with parent " + super.getClass());
     System.out.println("2 " + this.getClass() + " with parent " + this.getClass().getSuperclass());
     System.out.println("2 " + this.getFoo() + " with parent " + super.getFoo());
   //  System.out.println(this.getFoo() + " with parent " + this.getClass().getFoo());
    }
    public static void main(String[] args) {
      Untitled1 untitled12 = new Untitled2();
    }
    public String getFoo() {
      return "untitled2 foo";
    }
  }

2001-Jun-14 11:57am gyles19@visi.com
[Append to This Answer]
2001-Jun-14 11:57am
Previous: (Answer) The serialVersionUID from classes compiled by JB4 doesn't match Sun's javac 1.3 or 1.4.
Next: (Answer) We have some code which builds OK with Sun's JDK 1.3 javac, but gives the following error message when built with JBuilder3: "cannot reference variable markerList before superclass constructor has been called". Will upgrading to JB4 solve this problem?
This document is: http://www.visi.com/~gyles19/cgi-bin/fom.cgi?file=202
[Search] [Appearance]
This is a Faq-O-Matic 2.709.
This FAQ administered by gyles19@visi.com.

Other JBuilder Links

Java Community
Java Tools
Code Central
JB OpenTools
Community
Recent
Threads
Borland Chat
Chat FAQ
Feature Matrices
3.0 |  3.5 |  4.0
5.0 |  6.0 |  7.0
Shop for
JBuilder
JBuilder
Downloads
and reg keys
Report Piracy
Online Manuals
4.0 |  5.0 |  6.0
7.0
Borland
DevSupport's
Bug/RFE Form

Quality Central Client
JB Patches &
Updates
JBuilder FAQs TIs
JBuilder
Newsgroups
Tamaracka's
News Archive
Mr. Haki's
JBuilder Machine
JGuru's
JBuilder FAQ
Sun's Bug
Parade
Netring Home - About - Privacy
The
JBuilder Netring Logo
The Borland JBuilder Netring by JBuilder FAQ-O-Matic
[ Join Now | List Sites | Random | << Prev | Next >> ]
[ Previous 5 Sites | Skip Previous | Skip Next | Next 5 Sites ]