Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
178 views
in Technique[技术] by (71.8m points)

Why does this Java method appear to have two return types?

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?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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>


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...