3

Could anyone suggest how the code below could be re-written such that it works with JDK 1.6, please?

private Map<SocketChannel, byte[]> dataTracking = new HashMap<>();
Mureinik
  • 297,002
  • 52
  • 306
  • 350
  • 1
    `private Map dataTracking = new HashMap();`, perhaps? – Kevin Anderson Oct 20 '18 at 08:10
  • 1
    Simply remove the `<>` and you‘re done. – dpr Oct 20 '18 at 08:11
  • 2
    Sorry Kevin Anderson and dpr - you are giving bad advice! You're telling Stephen to use [raw types](https://stackoverflow.com/questions/2770321/what-is-a-raw-type-and-why-shouldnt-we-use-it). Do not use raw types, they only exist for backward compatibility with old Java versions. – Jesper Oct 20 '18 at 08:30
  • 1
    @Jesper question had invalid formatting with code `Map dataTracking = new HashMap<>();` – GotoFinal Oct 20 '18 at 08:31
  • @GotoFinal Even then it would have been better to tell Stephen to use generics and not raw types. – Jesper Oct 20 '18 at 08:35
  • @Jesper that said, it makes no difference in this case, except a warning. – Peter Lawrey Oct 20 '18 at 09:59
  • 1
    @PeterLawrey yes, but we shouldn't teach people who are new to Java bad habits. The only excuse to using raw types is when you have to work with very old code (before Java 5) which you cannot change. – Jesper Oct 20 '18 at 13:50

1 Answers1

8

Java 6 doesn't support the diamond operator. You'll have to copy the generic specification to the new call too:

private Map<SocketChannel, byte[]> dataTracking = new HashMap<SocketChannel, byte[]>();
Mureinik
  • 297,002
  • 52
  • 306
  • 350