For Programmers: Free Programming Magazines  


Home > Archive > Java Security > October 2004 > On java.lang.Class.getMethods()









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author On java.lang.Class.getMethods()
Grisha

2004-10-11, 3:57 am

Hi all,

What is the reason that getMethods() method (in java.lang.Class)
return only
public methods? After all, couldn't it return all methods, and then,
upon
invocation, throw a SecurityException (or IllegalAccessException)?
What
is the rationale for this?

-----

P.S. After reading http://www.yoda.arachsys.com/java/newsgroups.html,
http://mindprod.com/jgloss/newsgroups.html and
http://www.faqs.org/faqs/computer-l.../help/minifaq/, I do feel
this cross-post is justified. If there's a more authoritative source,
please point them out to me. Advocacy was chosen because this is a
point
of Sun's choice, and security -- because this is related to access of
methods.
jarekr

2004-10-11, 3:57 am


> What is the reason that getMethods() method (in java.lang.Class)
> return only
> public methods? After all, couldn't it return all methods, and then,
> upon
> invocation, throw a SecurityException (or IllegalAccessException)?
> What
> is the rationale for this?


Seen getDeclaredMethods()?

There are two functions because:
- getMethods() exhibits all methods that "object" of class implements, (including inherited),
- getDeclaredMethods() exhibits only methods declared in "class" (including private, not including
inherited)

so getDeclaredMethods() is more powerful... but in most cases less convenient than simple getMethods().

--
jarekr

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com