Why getResourceAsStream method is in Class class?

anu*_*sth 7 java embedded-resource java-me

Why public InputStream getResourceAsStream(String name) is in Class class? It just give inputstream of file which is in jar file and there is no relation with Class class. so it can be static method and it can be in any class.

Jon*_*eet 10

还有就是对类的关系:

  • 课程的包装被考虑在内 - 如果你打电话getResourceAsStream("baz.txt")给课程,foo.bar.SomeClass它会寻找/foo/bar/baz.txt
  • 首先考虑类加载器以查找资源 - 如果它是静态方法,它将如何知道要查看哪些jar文件(等)?生命比系统类加载器更重要