关于EncodedImage类create(String i)方法的参数及Javadoc疑问
Clarifying
EncodedImage.create(String i): Parameter Meaning & Javadoc Issues Great catch on the Javadoc problem—let's unpack this method thoroughly:
What the String i parameter actually represents
Looking at the method's implementation:
public static EncodedImage create(String i) throws IOException { return create(Display.getInstance().getResourceAsStream(EncodedImage.class, i)); }
This is a convenience wrapper that delegates to the create(InputStream) overload. The i string is the path or name of an image resource bundled with your application.
How getResourceAsStream uses this path:
- If you pass a simple filename like
icon.png, it looks for the file in the same package as theEncodedImageclass. - If you use a leading slash like
/assets/background.jpg, it looks for the file from the root of your application's resource directory.
Confirming the Javadoc error
You're 100% correct—this Javadoc is broken, and it looks like a copy-paste mistake from the create(InputStream) method:
/**
- Creates an image from the input stream
- @param i the resource
- ...
*/
Two key issues here:
- The main description says "Creates an image from the input stream"—but this method takes a string, not an input stream.
- The
@paramdescription is extremely vague: "the resource" tells developers nothing about what the string actually is (a resource path).
A fixed, clear Javadoc would be:
/** * Creates an image from a bundled application resource file. * * @param resourcePath the path or name of the bundled image resource to load * @return newly created encoded image * @throws java.io.IOException if the resource cannot be located, or an error occurs reading the resource stream */
内容的提问来源于stack exchange,提问作者Francesco Galgani
相关产品推荐
相关产品推荐

