You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bcel-user@jakarta.apache.org by David Hovemeyer <da...@cs.umd.edu> on 2002/10/25 22:27:39 UTC

strange line of code in ObjectType constructor

The constructor for org.apache.bcel.generic.ObjectType is defined as:

  /**
   * @param class_name fully qualified class name, e.g. java.lang.String
   */ 
  public ObjectType(String class_name) {
    super(Constants.T_REFERENCE, "L" + class_name.replace('.', '/') + ";");
    this.class_name = class_name.replace('/', '.');
  }

What is the meaning of the second line of code?  It looks
useless, because '/' is not a legal character in a class name.
Or am I missing something?

-Dave

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: strange line of code in ObjectType constructor

Posted by David Hovemeyer <da...@cs.umd.edu>.
On Fri, Oct 25, 2002 at 11:12:27PM +0200, Peter Schneider wrote:
> BCEL is a bytecode editing package and the bytecode classname contain
> '/'.
> for example Object is refered as 
> 	Ljava/lang/Object;
> 
> Other mail:
> Class names always include the full qualified package.
> As long as we are talking about bytecode there is nothing ambigous about
> it.

OK, I think I understand now.  My main source of confusion was the
Javadoc comment for the ObjectType constructor:

  /**
   * @param class_name fully qualified class name, e.g. java.lang.String
   */ 
  public ObjectType(String class_name) {
    ...

It suggests that the class_name parameter is the class name in the
same form it would appear in the source code.  It would be nice if it
explicitly stated how inner classes were handled, e.g.:

 /**
  * @param class_name fully qualified class name, e.g. java.lang.String
  *    or java.util.Map$Entry
  */

Thanks for your help.

-Dave

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: strange line of code in ObjectType constructor

Posted by Peter Schneider <sc...@lathanda.de>.
> -----Original Message-----
> From: David Hovemeyer [mailto:daveho@cs.umd.edu] 
> Sent: Friday, October 25, 2002 10:28 PM
> To: bcel-user@jakarta.apache.org
> Subject: strange line of code in ObjectType constructor
[...]
> class_name.replace('.', '/') + ";");
[...]
> What is the meaning of the second line of code?  It looks
> useless, because '/' is not a legal character in a class name.
> Or am I missing something?
BCEL is a bytecode editing package and the bytecode classname contain
'/'.
for example Object is refered as 
	Ljava/lang/Object;

Other mail:
Class names always include the full qualified package.
As long as we are talking about bytecode there is nothing ambigous about
it.

Innerclasses are refered with $. The '.' notation is only for
sourcecode.
The point is, that inner classes don't exist on bytecode level anymore.
Inner classes are transformed to a normal class with $ in it's name.
If A has an inner class B the name of B in bytecode is
A$B. The access rights that inner classes need are realized by adding
access methods with protected access rights.

I'm quiet sure you never will be able to load an inner class with A.B.
It will not be found.

Peter


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>