Posts5 [Effective Java] Item 45: Use streams judiciously 1 Creating streams Before I started this topic, there were some preliminaries that I had to be familiar with. You know those times when you try to get a stream of SomeType, but instead you get a stream of List instead? The following examples will clarify them: 1.1 int[] array stream Arrays.stream(int[]) - returns IntStream Arrays.stream(Integer[]) - returns Stream Stream.of(int...) - returns Str.. 2021. 11. 13. [Effective Java] Item 43: Prefer method reference to lambda Motivation Method reference is something I always tried to get into. However, always felt a little bit too overwhelming for me when I tried to get into it, because unlike lambda (which also took a great deal to get used to), method reference comes in different flavours (static method reference, instance method reference..) I am now a tiny bit confident that I understand about method reference. S.. 2021. 11. 8. [Effective Java] Item 42: Prefer lambda to anonymous classes In the previous post (Item 38: emulate extensible enums with interfaces), we had an enum declaration that implements different behaviour of overriden method for each enum instance. Just to refresh memory, here's what we had: An advantage of this is extreme flexibility - GradeCalculable interface's abstract method is implemented all differently for each enum instance. However, the fallpit of this.. 2021. 11. 7. [Effective Java] Item 38: emulate extensible enums with interfaces Enums cannot be extended. What does that mean? If we have an enum, and it had a method, then we cannot create another enum that implements the same method signature while being under the same type. There's a workaround for that. You can make enum implement an interface. This interface becomes the super type that can be extended by other enums. GradeCalculable Interface YearLevel Enum Advantage 1.. 2021. 11. 6. [Effective Java] Item 37: Using EnumMap as a way to group items by enum Why should you read this article? - You want to group collection into different groups, by enum. - You want to avoid using Set[] and use Map, but want to minimise memory consumption (ie not use HashMap, but something equivalent in memory consumption to simple array that is fixed sized) Let's get started! Oftentimes, a list (or any kind of collection) might need to be grouped into separate groups.. 2021. 11. 5. 이전 1 다음