Java Generics WildCards - What is wildcard in Java generic?

preview_player
Показать описание
Learn how to use wildcards in Java generics. A wildcard in Java generics is symbolised with a question mark (?). We can use wildcards to ease the restrictions on what type can be used in our generic methods.

Timestamp:
00:00 Generic Wildcards
00:33 Creating Generic Class
01:07 Create Object Of Generic Class
01:55 Generic Type Inference
03:45 Create Method To Accept Generic Type
06.50 Why We Need Generic Wildcards
06:40 Using Generic Wildcards

Connect With Lemubit Academy 🔍:
Рекомендации по теме
Комментарии
Автор

You saved my day bro. I am learning masterclass(Tim) of JAVA in udemy. I couldn't understand the main target to grasp as he was going very complicated detailing. I said you are the best because you explain the topic without any other contaminations. 😄

ramcharanPhirangi
Автор

yes, but it is only because you're using var as type. If you set properly your types for each array, it will still work with type parameters

var countries = new String[]{"Nigeria", "India", "USA", "Germany"};
var scores = new Integer[]{22, 46, 66, 92};
var names = new String[]{"John", "James", "Daniel"};

Store store1 = new Store<>(countries);
Store store2 = new Store<>(scores);
Store store3 = new Store<>(names);

store1.greaterThan(store2); // will compile properly

Dan-fivw
Автор

Thanks! You took a very good example for explaining Wildcards!

axelmund
Автор

I m using jdk 14 but ot does not support var why

waqasbhatti
Автор

We could use generic method to solve that why wildcard

souravprajapati
Автор

An okay explanation for someone who already knows what generics are and has run into the wildcard. Otherwise what happened to encapsulation that is supposed to be at the very first levels? Public class variables? tsk tsk ;)

thearchitecht