AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Possible to use reflection to get constructor params/args

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
Petterson Mikael
Guest





PostPosted: Wed Jun 28, 2006 6:31 pm    Post subject: Possible to use reflection to get constructor params/args Reply with quote



Hi,

Is it possible to use reflection to get the param/arg names i and d in
second constructor? ( I am using jdk 1.4).

cheers,

//mikael

public class Constructor1 {
public Constructor1()
{
}

protected Constructor1(int i, double d)
{
}
}
Back to top
Hendrik Maryns
Guest





PostPosted: Wed Jun 28, 2006 6:50 pm    Post subject: Re: Possible to use reflection to get constructor params/arg Reply with quote



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Petterson Mikael schreef:
Quote:
Hi,

Is it possible to use reflection to get the param/arg names i and d in
second constructor? ( I am using jdk 1.4).

cheers,

//mikael

public class Constructor1 {
public Constructor1()
{
}

protected Constructor1(int i, double d)
{
}
}

The names are absolutely meaningless, except in the inners of the
method, so there is absolutely no reason to want to get them. What do
you REALLY want?

H.
- --
Hendrik Maryns

==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFEookbe+7xMGD3itQRAtcdAJ9Q6A8LgNjJEKlQ/yxgaQLoJQho/ACdF/N1
3QTlA9M1/kB+HXOiqwxsvCM=
=A+Kz
-----END PGP SIGNATURE-----
Back to top
Thomas Hawtin
Guest





PostPosted: Wed Jun 28, 2006 9:27 pm    Post subject: Re: Possible to use reflection to get constructor params/arg Reply with quote



Petterson Mikael wrote:
Quote:

Is it possible to use reflection to get the param/arg names i and d in
second constructor? ( I am using jdk 1.4).

No, the information is not present in the source file.

There are a number of workarounds:

o APT (introduced in 1.5, part of javac in 1.6) gives access to
parameter names (it works on source). For instance see:
http://weblogs.java.net/blog/emcmanus/archive/2006/06/intermxbean_ref.html

o Run some form of parser on your source to store the information in a
convenient format. You could use a complete parser (like APT), or add
tags within comments to the source.

o Compile with variable name debugging enabled, and use ASM (or
similar) to read the class file.

o Compile with line number and file name debugging. Read the
information for the constructors with either ASM or arrange for an
exception to be thrown/created (and parse the stack trace). Use a regex
to extract the information from the source (which will need to be easy
to regex). See: http://www.jroller.com/page/cpurdy?entry=yaul_trace

Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.