• 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 wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

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: 80493
455
  • 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: 80493
455
  • 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: 42109
934
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