0

I was surfing in SO & I found syntax in Java as below:

String.class.getDeclaredField("value");

I could not understand how it works

Example:

In System.out.println(); out is static variable in System class of PrintWriter

Can any one explain what String.class.getDeclaredField("value"); and it's returning object of Field class means?

I just looked & I couldn't find class property(field) in String class.

What is it actually doing?

Thanks in advance.

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348

2 Answers2

1

String.class is a literal that represents the String class which is of type Class<String>. getDeclaredField() is a method defined on the class Class.

see also: What is a class literal in Java?

The literals are defined in the Java Language Specification 15.8.2

Community
  • 1
  • 1
Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
0

Look up Java Reflection API and Class.getDeclaredField().

Keerthivasan
  • 12,760
  • 2
  • 32
  • 53
keshlam
  • 7,931
  • 2
  • 19
  • 33
  • Thanks for the cosmetic cleanup, Octopus. I've been up all night, so was a bit more terse than optimal. – keshlam Jan 29 '14 at 11:07