-6

Is this declaration

// version 1
EnumMap<Type, EnumSet<Part>> types = new EnumMap<>(Type.class);

the same as this:

// version 2
var types = new EnumMap<Type, EnumSet<Part>>(Type.class);

I think it's the same, because I can also write this:

EnumMap<Type, EnumSet<Part>> types = new EnumMap<Type, EnumSet<Part>(Type.class);

and therefore this:

// version 2
var types = new EnumMap<Type, EnumSet<Part>>(Type.class);

Are there any differences in version 1 and version 2? Which should I prefer?

nimo23
  • 5,170
  • 10
  • 46
  • 75
  • 4
    *"Is this declaration...the same as this..."* I'm not versed enough in Java's `var` to say for *sure*, but...what else could either of them mean? :-) – T.J. Crowder Jun 08 '19 at 13:37
  • When you have to ask such questions, you should prefer variant 3. – Holger Jun 11 '19 at 15:57

1 Answers1

0

Yes, version 1 and 2 are the same.

nimo23
  • 5,170
  • 10
  • 46
  • 75