Class & interface terminology
Kevin Bourrillion
kevinb at google.com
Thu May 7 22:17:44 UTC 2020
[TL;DR: just agreeing]
As annoying as the constant use of the phrase "class or interface" must be
for everyone*, I definitely approve of all attempts to reserve use of the
word "type" for when we are talking about, er, types. Classes/interfaces
being just the flat, kinda sterile things that (most of) the crazy panoply
of types (things that can appear in type contexts) emerge out of.
The difference matters. To bore you with an example, in my nullness project
it's helped to cleanly distinguish a class member ("the Map class has the
class member keySet, returning Set<K>") from a "type member" ("the type
Map<String, Long> has the type member keySet, returning Set<String>"). It's
clearer to think of the type members as the things that get inherited from
supertypes, not the class members being inherited from
superclasses/interfaces.
So anything that helps separate these terms properly from each other is a
good move to me.
* by the way, it would be kinda nice if an informational sidebar in the JLS
would point that that its usage of the word "class" to be exclusive of
interfaces is unusual in almost all other contexts (class file, class
loader, `Class<?> c = Foo.class`, class initialization, class member, etc.)
If you've seen the Google style guide, the first thing I had to write was
"herein we say 'class' to mean what the JLS calls 'class or interface'. :-)
Because the difference just doesn't matter often enough.
On Thu, May 7, 2020 at 11:51 AM Dan Smith <daniel.smith at oracle.com> wrote:
I'll add that it's useful to think in terms of three different entities:
>
> 1) Class and interface declarations. These are syntax. Example: "interface
> List<E> ..."
> 2) Classes and interfaces. These are "symbols". Example: the interface List
> 3) Class and interface types. These are a kind of type. Example: the type
> List<String>
>
*Arguably* there is a useful 2.5) as well, the generic type List<E>
"itself" -- though it is not a reference type, only parameterizations of it
are. On the other hand, maybe that as its own concept is actually useless.
--
Kevin Bourrillion | Java Librarian | Google, Inc. | kevinb at google.com
More information about the amber-spec-observers
mailing list