4

I'm new to reflection, as a matter of fact, I never had to use it until I ran into the following problem -

I tried to use a method called getCompatibilityInfo defined in a class called Resources, but I saw that the only way of doing it is to call it like this:

Resources.class.getMethod("getCompatibilityInfo");

I can get an instance of Resources using a method called getResources(), so why isn't it accessible using getResources().getCompatibilityInfo()?

The class source code is here

Thanks!

Ron Tesler
  • 1,146
  • 1
  • 11
  • 24
  • because instanciating Resources is not sufficient. you have seen the code, you know there are certain parameters to the constructor, and the empty constructor is private, because it serves only for the System resources. – njzk2 Jun 05 '13 at 08:04
  • 3
    because of `@hide` annotation see http://stackoverflow.com/questions/7888191/how-do-i-build-the-android-sdk-with-hidden-and-internal-apis-available – farincz Jun 05 '13 at 08:09
  • @Heuster, it doesn't compile. – Ron Tesler Jun 05 '13 at 08:14
  • farincz, I'm looking for more info about the @hide annotation. Thanks. – Ron Tesler Jun 05 '13 at 08:15

2 Answers2

2

Resources has not an empty public constructor. So new Resources() will give you a compile time error, also getCompatibilityInfo() is not part of the public API

Blackbelt
  • 156,034
  • 29
  • 297
  • 305
  • You're right, I forgot to write it the right way. I edited my question and now I use getResources to obtain an instance. Still, it doesn't compile... – Ron Tesler Jun 05 '13 at 08:13
2

That's something that only happens in Android, because android.jar has all the methods marked with @hide removed. This only matters while compiling, because android.jar is only used for development.

Long explanation on this answer.

Community
  • 1
  • 1
Pablo
  • 3,655
  • 2
  • 30
  • 44