Multiple return types in Java

0 votes
public <E extends Foo> List<E> getResult(String s);

where Foo is my own class.

What is the return type of this method? Why does it seem to have two return types?

Feb 8, 2019 in Java by Sushmita
• 6,920 points
7,427 views

1 answer to this question.

0 votes

No, you don't have two return types.It's a generic method you are seeing.

 <E extends Foo> --> you are declaring a generic type for your method

 List<E> --> this is your return type

Your method can have a generic type E which is a sub-class of Foo. your return type is a List<Foo or any SubType Of FOO>

answered Feb 8, 2019 by developer_1
• 3,350 points

Related Questions In Java

0 votes
1 answer

Multiple return statements in Java

Yes, you have guessed it right. Language ...READ MORE

answered Jun 28, 2018 in Java by geek.erkami
• 2,680 points
2,165 views
0 votes
1 answer

In Java, how to find out the min/max values from array of primitive data types?

import java.util.Arrays; import java.util.Collections; import org.apache.commons.lang.ArrayUtils; public class MinMaxValue { ...READ MORE

answered Jun 12, 2018 in Java by Daisy
• 8,140 points
1,650 views
0 votes
2 answers

Can we catch multiple exceptions in the same catch clause in Java?

In Java 6 and before versions, we ...READ MORE

answered Aug 10, 2018 in Java by sharth
• 3,370 points
1,409 views
0 votes
2 answers

How to return multiple objects from a Java method?

In the event the method you're calling ...READ MORE

answered Aug 30, 2019 in Java by Karan
• 19,610 points
9,126 views
0 votes
2 answers

“Could not find or load main class” mean?

Use the final modifier to enforce good initialization. Avoid returning ...READ MORE

answered Sep 18, 2018 in Java by Sushmita
• 6,920 points
4,519 views
0 votes
2 answers

What is the use of toString method in Java and how can I use it ?

Whenever you require to explore the constructor ...READ MORE

answered Aug 23, 2018 in Java by Daisy
• 8,140 points
4,108 views
0 votes
2 answers

How do I replace character from string at specific indexes?

You could turn the String into a ...READ MORE

answered Aug 22, 2019 in Java by Sirajul
• 59,230 points
23,780 views
0 votes
2 answers

When to use Static Methods in Java?

A static method has two main purposes: For ...READ MORE

answered Aug 10, 2018 in Java by samarth295
• 2,220 points
16,072 views
0 votes
3 answers

Check if a String is numeric in Java

Java 8 Lambda Expression is used: String someString ...READ MORE

answered Sep 3, 2018 in Java by Daisy
• 8,140 points
3,702 views
0 votes
3 answers

How can I add new elements to an Array in Java

String[] source = new String[] { "a", ...READ MORE

answered Sep 19, 2018 in Java by Sushmita
• 6,920 points
13,208 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP