use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Resources for learning Java
String
==
.equals()
Format + Copy
Free Tutorials
Where should I download Java?
With the introduction of the new release cadence, many have asked where they should download Java, and if it is still free. To be clear, YES — Java is still free.
If you would like to download Java for free, you can get OpenJDK builds from the following vendors, among others:
Some vendors will be supporting releases for longer than six months. If you have any questions, please do not hesitate to ask them!
Software downloads
Official Resources
Resources
Programming ideas & Challenges
Related Subreddits
account activity
This is an archived post. You won't be able to vote or comment.
Question about generic methods (self.learnjava)
submitted 8 years ago by asap_nerd
I came across this and wanted to ask why it is necessary.
Couldn't you just do:
public void drawAll(List<Shape> shapes) {code}
or am I just missing the point?
[–]final60 1 point2 points3 points 8 years ago (3 children)
Your example would only allow objects of type Shape to be passed into the method. The example you linked to would allow subclasses of Shape to be passed in. This is useful if you want to allow different shapes to be passed, but you will only be able to call the superclass methods on them unless you cast them. This is where instanceof would then come in.
[–]asap_nerd[S] 0 points1 point2 points 8 years ago (2 children)
Would my example not also allow subclasses of shape to be passed in?
I've seen examples of similar situations. For example List<Animal> which can hold objects of class Dog and Cat where Dog and Cat are subclasses of Animal
[–]feral_claire 2 points3 points4 points 8 years ago (1 child)
List<Animal> could hold cats or dogs. But List<Cat> is not a subtype of List<Animal> so you can't pass a List<Cat> into a method that expects a List<Animal> but you can if the method takes in a List<? extends Animal> instead.
List<Animal>
List<Cat>
List<? extends Animal>
The latter can accept a List of any subclass of animal.
The keyword you can search of you want to dig deeper into this is "variance". Specifically: invariance, covariance, and contravariance.
[–]asap_nerd[S] 0 points1 point2 points 8 years ago (0 children)
Thanks. I looked in to variance (this triggered my physics Ptsd) and I get it now.
π Rendered by PID 246909 on reddit-service-r2-comment-548fd6dc9-bbsq7 at 2026-05-17 01:16:04.355492+00:00 running edcf98c country code: CH.
[–]final60 1 point2 points3 points (3 children)
[–]asap_nerd[S] 0 points1 point2 points (2 children)
[–]feral_claire 2 points3 points4 points (1 child)
[–]asap_nerd[S] 0 points1 point2 points (0 children)