0

I was reading this question in SO, and it contains the following:

A non-static nested class (sometimes incorrectly referred to as an 'inner class') (...)

And it confused me. At 350+ upvotes, I assume that the answer is basically correct, and I did further research on the difference between "non-static nested class" and "inner class" to find out why is it incorrect to call one by the other.

The Oracle tutorial (canonical?):

Terminology: Nested classes are divided into two categories: static and non-static. Nested classes that are declared static are called static nested classes. Non-static nested classes are called inner classes.

emphasis mine.

Robert "Corky" Cartwright wrote in his book:

class A {
      class B {
         // fields, methods of class B...
      }
      // fields, methods of class A...
}

(...)

A nested class like B is known as an inner class. (ref)

I'd like to dispel this confusion. In Java jargon, is it incorrect to refer to a non-static nested class as an inner class? If yes, why so?

  • 2
    People on Stack Exchange sometimes post incorrect information, that's all. The number of upvotes that an answer attracts is not a guarantee of factual correctness. To help you out, I've edited out the confusing (and probably inaccurate) portion of the answer. – Robert Harvey Jun 1 '16 at 21:05
  • I would consider both the Oracle tutorial and the Java Language Specification authoritative. – Robert Harvey Jun 1 '16 at 21:11
  • 1
    Also note that the assertion about the term inner class was added 6 years after the original posting of the answer, by someone other than the original author. (In other words, it was a bad edit.) – Sebastian Redl Jun 2 '16 at 11:54
4

According to the Java Language Specification s. 8.1.3,

"An inner class is a nested class that is not explicitly or implicitly declared static"

As this is the most authoritative document on the Java language, the answer to your question is no, it is not incorrect to use this term.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.