Java 10 also allows you to write var list = List.of("Carlos", "Joseph", "Terry", "Katherine"); when inside a method ('var' is not allowed on members).
Arrays.asList returns an ArrayList, so why wrap?
Here is a singleton in Java:
enum Foo {
INSTANCE;
}
and if you're mutating state in a singleton, in Kotlin or Java, you're doing it wrong.
Java is far too verbose for lots of things for sure. Especially for data class type use cases. But it is much better now than it was 5 years ago. Data class like things are on the way, though they probably won't be here for 2 years.
"and if you're mutating state in a singleton, in Kotlin or Java, you're doing it wrong."
Could you make an example with a real life scenario?
I had the idea that config files or something like a ShoppingCart as a Singleton is OK.
So taking the ShoppingCart as an example, I guess it would have a List<Product> products property that allows users to add() and remove() products from it. What could be an alternative?
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Java 10 also allows you to write
var list = List.of("Carlos", "Joseph", "Terry", "Katherine");
when inside a method ('var' is not allowed on members).Arrays.asList returns an ArrayList, so why wrap?
Here is a singleton in Java:
and if you're mutating state in a singleton, in Kotlin or Java, you're doing it wrong.
Java is far too verbose for lots of things for sure. Especially for data class type use cases. But it is much better now than it was 5 years ago. Data class like things are on the way, though they probably won't be here for 2 years.
Thanks for the tips Scott,
Regarding the Singleton:
Could you make an example with a real life scenario?
I had the idea that config files or something like a ShoppingCart as a Singleton is OK.
So taking the ShoppingCart as an example, I guess it would have a
List<Product> products
property that allows users toadd()
andremove()
products from it. What could be an alternative?