小编Sta*_*tov的帖子

在Java中生成致命错误

假设我们正在编写一个Java库,它提供了一些I/O ulitity函数,例如,一个方便的方法来读取文本文件作为字符串:

public class StringReader {

private static final Logger log = LoggerFactory.getLog(StringReader.class);

/**
 * Returns the contents of file <b>fileName</b> as String.
 * @param fileName file name to read
 * @return null on IO error
 */
public static String readString(String fileName) {
    FileInputStream fis = null;
    try {
        fis = new FileInputStream(fileName);
        byte[] data = new byte[fis.available()];
        fis.read(data);
        return new String(data, "ISO-8859-1"); // may throw UnsupportedEncodingException!
    } catch (IOException e) {
        log.error("unable to read file", e);
    } catch (UnsupportedEncodingException …
Run Code Online (Sandbox Code Playgroud)

java exception-handling

6
推荐指数
2
解决办法
6025
查看次数

Java泛型问题

我有这门课......

public class Entry <K, V> {
    private final K mKey;
    private final V mValue;

    public Entry() {  
        mKey = null;
        mValue = null;   
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我使用int作为mKey会发生什么?据我所知,整数不能为空!

java generics integer

1
推荐指数
1
解决办法
195
查看次数

标签 统计

java ×2

exception-handling ×1

generics ×1

integer ×1