0

Why is Android using $ sign to reference nested class, instead of standard . sign. As far as I know, in Java $ is related to inner class context (in stacktrace).

<view class="path.to.Outer$Nested" ... />

In data-binding . sign is being used to reference nested class as expected:

<variable name="..." type="path.to.Outer.Nested" />
matoni
  • 2,479
  • 21
  • 39

1 Answers1

1

Because the inner class is not static.

class Parent {

  class Child {
  }
}

would result in Parent$Child while

class Parent {

  static class Child {
  }
}

would be referenced as Parent.Child.

Robert Estivill
  • 12,369
  • 8
  • 43
  • 64
  • So it is possible to use inner class in XML (`inner = public class Outer{ public class ClassName{}}, nested = public class Outer{public static class ClassName{}}`)? I've read somewhere that view defined in outer class should always be static, which seems legit. Without static, inflater would require to have reference on outer class insteance in order to instantiate this inner class. – matoni Jun 29 '17 at 15:10
  • Don't know about databinding to be honest with you. Added an example on the answer to help make it clearer – Robert Estivill Jun 29 '17 at 15:29
  • But how it is even possible to use inner view (see my comment)? When I saw Parent$Child view, it was always static child i. e. nested class. – matoni Jun 29 '17 at 15:31