One of my readers asked me about the difference between ArrayList vs ArrayList< in Java?>, which was actually asked to him in a recent Java development interview. The key difference between them is that ArrayList is not using Generics while ArrayList is a generic ArrayList but they look very similar. If a method accepts ArrayList or ArrayList<?> as a parameter then it can accept any type of ArrayList like ArrayList of String, Integer, Date, or Object, but if you look closely you will find that one is raw type while the other is using an unbounded wildcard. What difference that could make? Well, that makes a significant difference because ArrayList with raw type is not type-safe but ArrayList<?> with the unbounded wildcard is type-safe.
Ads 970x90
Tampilkan postingan dengan label Java Generics Tutorial. Tampilkan semua postingan
Tampilkan postingan dengan label Java Generics Tutorial. Tampilkan semua postingan
Jumat, 22 Oktober 2021
Kamis, 29 Juli 2021
10 Interview Questions on Java Generics for Programmer and Developers
Generic interview questions in Java interviews are getting more and more common with Java 5 around there for a considerable time and many applications either moving to Java 5 and almost all new Java development happening on Tiger(code name of Java 5). The importance of Generics and Java 5 features like Enum, Autoboxing, varargs, and Collection utilities like CountDownLatch, CyclicBarrier, and BlockingQueue is getting more and more popular on Java interviews. Generic interview questions can get really tricky if you are not familiar with bounded and unbounded generic wildcards, How generics works internally, type erasure and familiarity with writing parametrized generics classes and methods in Java.
Rabu, 28 Juli 2021
What is bounded and unbounded wildcards in Generics Java? Example
Bounded and unbounded wildcards in Generics are two types of wildcards available on Java. Any Type can be bounded either upper or lower of the class hierarchy in Generics by using bounded wildcards. In short <? extends T> and <? super T> represent bounded wildcards while <?> represent an unbounded wildcard in generics. In our last article How Generics works in Java, we have seen some basic details about bounded and unbounded wildcards in generics and In this Java tutorial, we will see bounded and unbounded generics wildcards in detail.
The Ultimate Guide of Generics in Java - Examples
Java Generics Tutorial
Generics in Java is one of the important features added in Java 5 along with Enum, autoboxing, and varargs, to provide compile-time type-safety. Generics are also considered to be one of the tough concepts to understand in Java and somewhat it’s true as well. I have read many articles on generics in Java, some of them are quite good and detailed but I still felt that those are either too technical or exhaustively detailed, so I thought to write a simple yet informative article on Java generics to give a head start to beginners without bothering their head too much.