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 in Java by Sushmita
• 6,880 points
29 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 by developer_1
• 3,300 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 27, 2018 in Java by geek.erkami
• 2,640 points
91 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,050 points
104 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,350 points
153 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 in Java by Karan
• 6,060 points
136 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,880 points
1,827 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,050 points
846 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 in Java by Sirajul
• 39,540 points
52 views
0 votes
2 answers

When to use Static Methods in Java?

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

answered Aug 9, 2018 in Java by samarth295
• 2,190 points
118 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,050 points
831 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,880 points
153 views