Forums Register Login

Map instantiate with key-value

+Pie Number of slices to send: Send
How can I do this in one line?



Something like:

+Pie Number of slices to send: Send
Unless I'm missing something obvious, the API does not allow you to do it. Is it bothering you to put it in different lines ?
+Pie Number of slices to send: Send
 

Originally posted by Christophe Verre:
Unless I'm missing something obvious, the API does not allow you to do it. Is it bothering you to put it in different lines ?



Hi , i think Christophe is right API doesn't allow this check this for more deatils
+Pie Number of slices to send: Send
You can create an anonymous subclass with an initializer block:

I wouldn't do that though, since a) it's confusing, and b) it's longer than just calling the put methods.
+Pie Number of slices to send: Send
I wouldn't call Rob's trick to be one line long
+Pie Number of slices to send: Send
okay thanks.

It does not matter, I was just wondering, if it would be possible with anonymous declarations or the like.

thanks
+Pie Number of slices to send: Send
 

Originally posted by Christophe Verre:
I wouldn't call Rob's trick to be one line long


But it can be; just remove all the enters

This is actually similar to how .NET 3.0 and up handle object initialization; the inner bracket pair is removed but the rest is the same.
Does this tiny ad smell okay to you?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 24525 times.
Similar Threads
if isEmpty or null
jaxb hashmap?
IllegalArgumentException: more than 10 parameters
HashMap Construction with initial values
JSP variable into javascript
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 08:00:49.