3

1) when the lifetime of static nested class in Java begins? can static inner class be used before creation of the containing object?

I'm asking because I encountered the code:

  LinearLayout.LayoutParams layoutParams1 = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);

and I tried to answer the question:

2) what is LayoutParams to LinearLayout?

anyway if what I suspect doesn't relate to the syntax I would like to get answers for both 1 & 2.

Day_Dreamer
  • 3,142
  • 5
  • 33
  • 60
  • possible duplicate of [Java static class initialization](http://stackoverflow.com/questions/3499214/java-static-class-initialization) – yitzih Mar 05 '15 at 02:23
  • Is there a way I could know it? it looks to me like the syntax to create an object for a static nested class – Day_Dreamer Mar 05 '15 at 02:24

1 Answers1

4

An instance of a static nested class can be created without creating an instance of its outer class.

"static inner class" is an incorrect expression. JLS 8.1.3: An inner class is a nested class that is not explicitly or implicitly declared static.

LayoutParams is a static nested class of LinearLayout. LinearLayout is outer class of LayoutParams

Evgeniy Dorofeev
  • 129,181
  • 28
  • 195
  • 266