Difference between List and List<ClassWhat is a difference between <? super E> and <? extends E>?The difference between Classes, Objects, and InstancesDifferences between HashMap and Hashtable?Java inner class and static nested classWhat is the difference between public, protected, package-private and private in Java?Difference between StringBuilder and StringBufferDifference between wait() and sleep()Difference between HashMap, LinkedHashMap and TreeMapDifference between <? super T> and <? extends T> in JavaWhat's the difference between @Component, @Repository & @Service annotations in Spring?What is the difference between canonical name, simple name and class name in Java Class?Ways to iterate over a list in Java
What factors could lead to bishops establishing monastic armies?
Can we share mixing jug/beaker for developer, fixer and stop bath?
What purpose does mercury dichloride have in fireworks?
Those who speak do not know, those who know do not speak
Will Jimmy fall off his platform?
When do flights get cancelled due to fog?
How to reclaim personal item I've lent to the office without burning bridges?
What's the difference between a type and a kind?
Quotients of a ring of integers
How did the Time Lords put a whole "Star" in a Tardis?
Examples of fluid (including air) being used to transmit digital data?
How do I talk to my wife about unrealistic expectations?
What are the consequences for a developed nation to not accept any refugee?
Why is whale hunting treated differently from hunting other animals?
How beneficial are flaps when landing with a tailwind?
Why did Robert F. Kennedy loathe Lyndon B. Johnson?
As a supervisor, what feedback would you expect from a PhD who quits?
Why do airports remove/realign runways?
Interpretation of non-significant results as "trends"
What does the multimeter dial do internally?
What was the nature of the known bugs in the Space Shuttle software?
What does "frozen" mean (e.g. for catcodes)?
Why do Martians have to wear space helmets?
What are the effects of abstaining from eating a certain flavor?
Difference between List super T> and List
What is a difference between <? super E> and <? extends E>?The difference between Classes, Objects, and InstancesDifferences between HashMap and Hashtable?Java inner class and static nested classWhat is the difference between public, protected, package-private and private in Java?Difference between StringBuilder and StringBufferDifference between wait() and sleep()Difference between HashMap, LinkedHashMap and TreeMapDifference between <? super T> and <? extends T> in JavaWhat's the difference between @Component, @Repository & @Service annotations in Spring?What is the difference between canonical name, simple name and class name in Java Class?Ways to iterate over a list in Java
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I was going through generics in Java and I'm having trouble trying to understand where I would use the following two.
I understand that the first myList
would ensure that the list only contains elements of type Integer
and all it's superclasses. Now I'm trying to figure out where myList2
would fit in here.
List<? super Integer> myList;
List<Class<? super Integer>> myList2;
Edit: It's not a duplicate of the question being linked...since this is clearly regarding the use of ?
vs Class<?
whereas the other question is about super
vs extend
java
|
show 1 more comment
I was going through generics in Java and I'm having trouble trying to understand where I would use the following two.
I understand that the first myList
would ensure that the list only contains elements of type Integer
and all it's superclasses. Now I'm trying to figure out where myList2
would fit in here.
List<? super Integer> myList;
List<Class<? super Integer>> myList2;
Edit: It's not a duplicate of the question being linked...since this is clearly regarding the use of ?
vs Class<?
whereas the other question is about super
vs extend
java
myList2.add(Integer.class);
– Ruslan
Mar 25 at 21:32
Possible duplicate of What is a difference between <? super E> and <? extends E>?
– LppEdd
Mar 25 at 21:32
2
myList
is a list of object instances, e.g. aList<Number>
storingInteger
,Double
,BigDecimal
, ... objects, such as42
,3.14159
,3e9876
, ... ---myList2
is a list ofClass
objects, i.e. a list ofInteger.class
,Number.class
,Object.class
,Serializable.class
, orComparable.class
values.
– Andreas
Mar 25 at 21:33
I understand the difference between super and extends. I was just wondering where myList2 would be used.
– AsadSMalik
Mar 25 at 21:33
1
I can't offhand think of a use for a list of class objects, but in general you use a Class object as a way to indicate type, or as a way to determine the properties of that type.
– another-dave
Mar 25 at 21:53
|
show 1 more comment
I was going through generics in Java and I'm having trouble trying to understand where I would use the following two.
I understand that the first myList
would ensure that the list only contains elements of type Integer
and all it's superclasses. Now I'm trying to figure out where myList2
would fit in here.
List<? super Integer> myList;
List<Class<? super Integer>> myList2;
Edit: It's not a duplicate of the question being linked...since this is clearly regarding the use of ?
vs Class<?
whereas the other question is about super
vs extend
java
I was going through generics in Java and I'm having trouble trying to understand where I would use the following two.
I understand that the first myList
would ensure that the list only contains elements of type Integer
and all it's superclasses. Now I'm trying to figure out where myList2
would fit in here.
List<? super Integer> myList;
List<Class<? super Integer>> myList2;
Edit: It's not a duplicate of the question being linked...since this is clearly regarding the use of ?
vs Class<?
whereas the other question is about super
vs extend
java
java
edited Mar 25 at 21:37
AsadSMalik
asked Mar 25 at 21:26
AsadSMalikAsadSMalik
3479 silver badges27 bronze badges
3479 silver badges27 bronze badges
myList2.add(Integer.class);
– Ruslan
Mar 25 at 21:32
Possible duplicate of What is a difference between <? super E> and <? extends E>?
– LppEdd
Mar 25 at 21:32
2
myList
is a list of object instances, e.g. aList<Number>
storingInteger
,Double
,BigDecimal
, ... objects, such as42
,3.14159
,3e9876
, ... ---myList2
is a list ofClass
objects, i.e. a list ofInteger.class
,Number.class
,Object.class
,Serializable.class
, orComparable.class
values.
– Andreas
Mar 25 at 21:33
I understand the difference between super and extends. I was just wondering where myList2 would be used.
– AsadSMalik
Mar 25 at 21:33
1
I can't offhand think of a use for a list of class objects, but in general you use a Class object as a way to indicate type, or as a way to determine the properties of that type.
– another-dave
Mar 25 at 21:53
|
show 1 more comment
myList2.add(Integer.class);
– Ruslan
Mar 25 at 21:32
Possible duplicate of What is a difference between <? super E> and <? extends E>?
– LppEdd
Mar 25 at 21:32
2
myList
is a list of object instances, e.g. aList<Number>
storingInteger
,Double
,BigDecimal
, ... objects, such as42
,3.14159
,3e9876
, ... ---myList2
is a list ofClass
objects, i.e. a list ofInteger.class
,Number.class
,Object.class
,Serializable.class
, orComparable.class
values.
– Andreas
Mar 25 at 21:33
I understand the difference between super and extends. I was just wondering where myList2 would be used.
– AsadSMalik
Mar 25 at 21:33
1
I can't offhand think of a use for a list of class objects, but in general you use a Class object as a way to indicate type, or as a way to determine the properties of that type.
– another-dave
Mar 25 at 21:53
myList2.add(Integer.class);
– Ruslan
Mar 25 at 21:32
myList2.add(Integer.class);
– Ruslan
Mar 25 at 21:32
Possible duplicate of What is a difference between <? super E> and <? extends E>?
– LppEdd
Mar 25 at 21:32
Possible duplicate of What is a difference between <? super E> and <? extends E>?
– LppEdd
Mar 25 at 21:32
2
2
myList
is a list of object instances, e.g. a List<Number>
storing Integer
, Double
, BigDecimal
, ... objects, such as 42
, 3.14159
, 3e9876
, ... --- myList2
is a list of Class
objects, i.e. a list of Integer.class
, Number.class
, Object.class
, Serializable.class
, or Comparable.class
values.– Andreas
Mar 25 at 21:33
myList
is a list of object instances, e.g. a List<Number>
storing Integer
, Double
, BigDecimal
, ... objects, such as 42
, 3.14159
, 3e9876
, ... --- myList2
is a list of Class
objects, i.e. a list of Integer.class
, Number.class
, Object.class
, Serializable.class
, or Comparable.class
values.– Andreas
Mar 25 at 21:33
I understand the difference between super and extends. I was just wondering where myList2 would be used.
– AsadSMalik
Mar 25 at 21:33
I understand the difference between super and extends. I was just wondering where myList2 would be used.
– AsadSMalik
Mar 25 at 21:33
1
1
I can't offhand think of a use for a list of class objects, but in general you use a Class object as a way to indicate type, or as a way to determine the properties of that type.
– another-dave
Mar 25 at 21:53
I can't offhand think of a use for a list of class objects, but in general you use a Class object as a way to indicate type, or as a way to determine the properties of that type.
– another-dave
Mar 25 at 21:53
|
show 1 more comment
2 Answers
2
active
oldest
votes
The first one, 'myList' may contain integer values. Example: myList.add(200);
The second one, 'myList2' may contain classes of type integer. Example: myList2.add(Integer.class);
Ok so like you mentioned in the comments, if instead of Integer, I'm extending Number, then the second list could contain elements Integer, BigDecimal etc.
– AsadSMalik
Mar 25 at 21:34
The first list might also contain e.g.String
values, because it might be aList<Object>
. --- The second list can also store classes of other types, e.g.Number.class
,Object.class
,Serializable.class
, andComparable.class
.
– Andreas
Mar 25 at 21:35
add a comment |
The first list contains objects of Integer and its superclasses.
The second one contains class objects (or simply classes) of Integer and its superclasses, i.e:
Integer.class;
Number.class;
You can read more about the differences here: The difference between Classes, Objects, and Instances
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55346644%2fdifference-between-list-super-t-and-listclass-super-t%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The first one, 'myList' may contain integer values. Example: myList.add(200);
The second one, 'myList2' may contain classes of type integer. Example: myList2.add(Integer.class);
Ok so like you mentioned in the comments, if instead of Integer, I'm extending Number, then the second list could contain elements Integer, BigDecimal etc.
– AsadSMalik
Mar 25 at 21:34
The first list might also contain e.g.String
values, because it might be aList<Object>
. --- The second list can also store classes of other types, e.g.Number.class
,Object.class
,Serializable.class
, andComparable.class
.
– Andreas
Mar 25 at 21:35
add a comment |
The first one, 'myList' may contain integer values. Example: myList.add(200);
The second one, 'myList2' may contain classes of type integer. Example: myList2.add(Integer.class);
Ok so like you mentioned in the comments, if instead of Integer, I'm extending Number, then the second list could contain elements Integer, BigDecimal etc.
– AsadSMalik
Mar 25 at 21:34
The first list might also contain e.g.String
values, because it might be aList<Object>
. --- The second list can also store classes of other types, e.g.Number.class
,Object.class
,Serializable.class
, andComparable.class
.
– Andreas
Mar 25 at 21:35
add a comment |
The first one, 'myList' may contain integer values. Example: myList.add(200);
The second one, 'myList2' may contain classes of type integer. Example: myList2.add(Integer.class);
The first one, 'myList' may contain integer values. Example: myList.add(200);
The second one, 'myList2' may contain classes of type integer. Example: myList2.add(Integer.class);
answered Mar 25 at 21:33
Andreas VoglAndreas Vogl
7735 silver badges12 bronze badges
7735 silver badges12 bronze badges
Ok so like you mentioned in the comments, if instead of Integer, I'm extending Number, then the second list could contain elements Integer, BigDecimal etc.
– AsadSMalik
Mar 25 at 21:34
The first list might also contain e.g.String
values, because it might be aList<Object>
. --- The second list can also store classes of other types, e.g.Number.class
,Object.class
,Serializable.class
, andComparable.class
.
– Andreas
Mar 25 at 21:35
add a comment |
Ok so like you mentioned in the comments, if instead of Integer, I'm extending Number, then the second list could contain elements Integer, BigDecimal etc.
– AsadSMalik
Mar 25 at 21:34
The first list might also contain e.g.String
values, because it might be aList<Object>
. --- The second list can also store classes of other types, e.g.Number.class
,Object.class
,Serializable.class
, andComparable.class
.
– Andreas
Mar 25 at 21:35
Ok so like you mentioned in the comments, if instead of Integer, I'm extending Number, then the second list could contain elements Integer, BigDecimal etc.
– AsadSMalik
Mar 25 at 21:34
Ok so like you mentioned in the comments, if instead of Integer, I'm extending Number, then the second list could contain elements Integer, BigDecimal etc.
– AsadSMalik
Mar 25 at 21:34
The first list might also contain e.g.
String
values, because it might be a List<Object>
. --- The second list can also store classes of other types, e.g. Number.class
, Object.class
, Serializable.class
, and Comparable.class
.– Andreas
Mar 25 at 21:35
The first list might also contain e.g.
String
values, because it might be a List<Object>
. --- The second list can also store classes of other types, e.g. Number.class
, Object.class
, Serializable.class
, and Comparable.class
.– Andreas
Mar 25 at 21:35
add a comment |
The first list contains objects of Integer and its superclasses.
The second one contains class objects (or simply classes) of Integer and its superclasses, i.e:
Integer.class;
Number.class;
You can read more about the differences here: The difference between Classes, Objects, and Instances
add a comment |
The first list contains objects of Integer and its superclasses.
The second one contains class objects (or simply classes) of Integer and its superclasses, i.e:
Integer.class;
Number.class;
You can read more about the differences here: The difference between Classes, Objects, and Instances
add a comment |
The first list contains objects of Integer and its superclasses.
The second one contains class objects (or simply classes) of Integer and its superclasses, i.e:
Integer.class;
Number.class;
You can read more about the differences here: The difference between Classes, Objects, and Instances
The first list contains objects of Integer and its superclasses.
The second one contains class objects (or simply classes) of Integer and its superclasses, i.e:
Integer.class;
Number.class;
You can read more about the differences here: The difference between Classes, Objects, and Instances
edited Mar 25 at 21:56
answered Mar 25 at 21:33
Pavel SmirnovPavel Smirnov
2,7692 gold badges9 silver badges18 bronze badges
2,7692 gold badges9 silver badges18 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55346644%2fdifference-between-list-super-t-and-listclass-super-t%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
myList2.add(Integer.class);
– Ruslan
Mar 25 at 21:32
Possible duplicate of What is a difference between <? super E> and <? extends E>?
– LppEdd
Mar 25 at 21:32
2
myList
is a list of object instances, e.g. aList<Number>
storingInteger
,Double
,BigDecimal
, ... objects, such as42
,3.14159
,3e9876
, ... ---myList2
is a list ofClass
objects, i.e. a list ofInteger.class
,Number.class
,Object.class
,Serializable.class
, orComparable.class
values.– Andreas
Mar 25 at 21:33
I understand the difference between super and extends. I was just wondering where myList2 would be used.
– AsadSMalik
Mar 25 at 21:33
1
I can't offhand think of a use for a list of class objects, but in general you use a Class object as a way to indicate type, or as a way to determine the properties of that type.
– another-dave
Mar 25 at 21:53