假设我们正在编写一个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) 我有这门课......
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会发生什么?据我所知,整数不能为空!