2

I can view the methods of a class using java reflection.

    Method[] methods = Person.class.getMethods();
    for(Method method : methods){
        System.out.println("method = " + method);
    }

the person class ,

class Person{
String name;
int age;

Person(String name,int age){
    this.name = name;
    this.age = age;
}
public int count(){
    int count = 10*20;
    return count;
} 
}

Using reflection the count method will view like, method = public int Person.count() but not the implementation (method body).

is there anyway to view the full implementation details of a method using this kind of approach or with any other ?

2 Answers 2

2

It's not possible to do this using standard Java tools. The source method implementation is not accessible in runtime. You can however load this class file as a resource and pass it to some Java decompiler, which will try its best to produce the original source code of the class. Or course it's not guaranteed that the result will be 100% exact and it will be even worse if your class is compiled without debugging information.

Sign up to request clarification or add additional context in comments.

Comments

1

There is a sourceforge project. It takes class file as input, decompiles it, provides the source file and is platform independent: Java Decompiler

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.