Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1
in future you can decide to use SoftwareEngineer instead Programmer, and if you use only Person methods this change is easy. (but I don't like this strategy too) upcasting is useful by method arguments and return type, then method can work with more types (all subtypes)
3rd Dec 2021, 3:03 PM
zemiak
+ 1
here it is necessary import java.util.*; public class MyClass { public static void main(String args[]) { /*java.util.ImmutableCollections.Map1<String,String> m = Map.of("aa","bb"); //error */ Map<String,String> map = Map.of("aa","bb"); System.out.println( map.getClass() ); map = Map.of("aa","bb","cc","dd"); System.out.println( map.getClass() ); } }
11th Jan 2022, 3:07 AM
zemiak