Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Java reflection to get method name

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
here is my class

package com;



The method1() is not a part of the op. Please explain!!

Thanks
Faisal Syed

[See UseCodeTags]
 
author
Posts: 23912
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Faisal syed wrote:Hi,
here is my class



The method1() is not a part of the op. Please explain!!



The Class.forName() method returns a Class instance for the class requested. Calling the getClass() method on that class object, will get you the Class instance for the Class class. And according to the JavaDoc, the java.lang.Class class doesn't have a method1() method.

Henry
 
Faisal syed
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When we speak of a singleton, I read in an article that an attacker may use the reflection API to gain unauthorised access to the members of your class. How can he gain access to the constructor < Singleton() >, or say any method not defined in the class Class?? Pleasae help!!!


 
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check the class AccessibleObject. You may find something useful there...
 
Henry Wong
author
Posts: 23912
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Faisal syed wrote:When we speak of a singleton, I read in an article that an attacker may use the reflection API to gain unauthorised access to the members of your class. How can he gain access to the constructor < Singleton() >, or say any method not defined in the class Class?? Pleasae help!!!






IMO, I think there are two distinct questions here...

For the question on how to access private components of the class, basically, the Field and Method classes have a setAccessible() method. If the method is called with true, the program will be able to access private fields and methods.

For the question on how to prevent access, these calls go through the security manager. And hence, not allowed for applets, RMI calls, etc. If you have a situation where you don't trust certain code, you need to configure your security manager appropriately.

Henry
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic