0

I now have this question because of a code review iteration, in which I created an POJO to be used as a request object, like this one:

class Request {
       private List<Item> items;
       static class Item{
           // ... some other stuff
       }
}

and then someone requested to extract the inner class because it was static, meaning that its instances would be treated as if they were automatically static, which would mean that we would only have an instance of type Item while the system was up and stuff, or at least there was that risk though.

I tried to respond by saying that that happens with static values, but this is a static class, which according to what I understand it only affects the way it is instantiated and the access it has to the enclosing classes' fields, but I couldn't find anything in the JLS (or anywhere to be honest) to explicitly support my claim.

Does anyone know whether the guy was right about requesting that change? If not, does anybody know where can I find information to support/prove my argument? Any pointer will do :) Thanks in advance!

Jose Ramirez
  • 381
  • 6
  • 20
  • Related question: [Java inner class and static nested class](https://stackoverflow.com/questions/70324/java-inner-class-and-static-nested-class) – Hovercraft Full Of Eels Mar 13 '20 at 01:10
  • 1
    Your question doesn't really make sense though, as instances (objects) can never be static or non-static. Only *variables* can be static or non-static – Hovercraft Full Of Eels Mar 13 '20 at 01:11
  • 'Static inner' is a contradiction in terms. – user207421 Mar 13 '20 at 01:24
  • 1
    The part beginning 'meaning that its instances would be treated as if they were automatically static ...' is completely meaningless. 'The guy' doesn't know what he's talking about. – user207421 Mar 13 '20 at 01:28
  • @HovercraftFullOfEels I was actually hoping that answer, hehehe! it's just that even though I agree with what you said (it's even in my question), I didn't have a convincing way to prove it at the time. Thank you! – Jose Ramirez Mar 13 '20 at 10:23
  • You don't need a way to prove it. It's not in the JLS: it isn't true. It's up to 'the guy' to prove his assertion. – user207421 Mar 13 '20 at 19:48
  • Specifically: 'someone requested to extract the inner class': there is no inner class here. 'Because it was static': that's not a reason to extract it. 'Meaning that its instances would be treated as if they were automatically static': no it doesn't. There is no such thing as a static instance of a class. 'Which would mean that we would only have an instance of type Item while the system was up': this is entirely meaningless. You can't have an instance of anything unless the system is up. 'And stuff': what stuff? 'Or at least there was that risk though': what risk? – user207421 Mar 14 '20 at 07:24

0 Answers0