简体   繁体   中英

How do you call a method in a .class File

So say you have a class file (No source code). And the only thing you need to know is there is a public static String[] getBookings() in that class file. How do you call that method to your main program?

If you use any 3rd party JAR, you'll have a .class file without .java source. That's common.

How do you do it? Easy - instantiate an instance and call the method if it's not a static method; call it on the class if it is.

public static void main(String [] args) {
    com.foo.Bar bar = new com.foo.Bar();
    String [] bookings = bar.getBookings();
}

将类文件添加到与.java文件相同的位置,然后尝试在.java文件中调用该方法。

you can use javap command on windows command line or unix shell if you have Java_Home/BIN in your classpath

http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javap.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM