开发者

throw new RuntimeException("Compiled Code")?

I've just looked into the code of javax.ws.rs.core.MediaType and wondered about throw new RuntimeException("Compiled Code"), since I've never seen that before. I think is a form of "not implemented", but don't know.

package javax.ws.rs.core;

import java.util.Map;
import javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate;

public class MediaType {

  // some variables and constants ...

  public static MediaType valueOf(String string) throws IllegalArgumentException {
    //compiled code
    throw new RuntimeException("Compiled Code");
  }

  public MediaType(String string, String string1, Map<String, String> map) {
    //compiled code
    throw new RuntimeException("Compile开发者_StackOverflow社区d Code");
  }

  public MediaType(String string, String string1) {
    //compiled code
    throw new RuntimeException("Compiled Code");
  }

  ...

}

What is it all about?


Based on the code fragment you posted i presume you are looking at a *.class file and not a *.java file?

If so, the "compiled code" and //compiled code are there because of your IDE trying to give you some readable representation of those compiled *.java classes, so you can at least take a look at what methods are available in that class.

The "compiled code" is in no manner the correct error message that is given when the RunTimeException is thrown.

The presentation of the *.class files is different in every IDE (eclipse, intelliJ, ..)

If you want to be able to take a look at the code that is executed, you will need the uncompiled *.java files.


You basically navigated to a Java Class file, which hasn't got attached any source file.

What you're seeing is MediaType.class file represented by NetBeans IDE. It's basically the same output as you would see by invoking javap MediaType.class. The exceptions are there only to warn You. It's not the true content of the file. You see only method signatures and public fields, since that's exposed by the .class file anyway. The rest is implementation which was omitted, since without source code, You can only get machine code (would You really like to dig into it? Most probably prefer to read other documentation, or find source on google).

JDK is divided into public and private programming interfaces. The public one is well documented and comes with source code. It's not always the same with private part of API.


To add to the other answers, you can view the .class file contents (executed instructions) using a decompiler. A good one is Java Decompiler at http://java.decompiler.free.fr/


I have the "same" code in a jar file. Recently I was working with this jar file and I don't know where can I view the code. After open the file in NetBeans, this is the result:

public class ConsolaEjecucion extends JFrame {

    private JPanel jContentPane;
    private JScrollPane jScrollPane;
    private JTextArea display;
    private JProgressBar barraProgreso;
    private JFrame frame;

    public ConsolaEjecucion(JFrame frame) {
        //compiled code
        throw new RuntimeException("Compiled Code");
    }

    private JPanel getJContentPane() {
        //compiled code
        throw new RuntimeException("Compiled Code");
    }

    ...

}

But, the functional code isn't present! Thanks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜