Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java - static nested class lifetime

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.

like image 601
Day_Dreamer Avatar asked Apr 15 '26 15:04

Day_Dreamer


1 Answers

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

like image 167
Evgeniy Dorofeev Avatar answered Apr 17 '26 06:04

Evgeniy Dorofeev