• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Sybex 816 - page 129: Map.of is not overloaded with odd parameter number

 
Greenhorn
Posts: 13
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The text on Map.of says Map.of("key1", "value1", "key2"); compiles and throws runtime error, but it does not compile. Map.of is only overloaded with even parameter numbers https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Map.html
 
Marshal
Posts: 74376
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, it is only overloaded to take pairs of “K”s and “V”s. It goes K, V or K, V, K, V or K, V, K, V, K, V, K, V etc.. So you can't have odd numbers of parameters, Where does it say such code compiles?
 
Jos Roseboom
Greenhorn
Posts: 13
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On page 129 in the section on Map.of() and Map.copyOf() is the fragment:



Right below that fragment the first line says:

This code compiles but throws an error at runtime.
 
Campbell Ritchie
Marshal
Posts: 74376
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaah! Is that where it comes from? Now I understand the problem. Thank you.
 
author & internet detective
Posts: 40798
829
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Confirmed and added to the errata
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic