为什么这个Java方法似乎有两种返回类型? [英] Why does this Java method appear to have two return types?

查看:79
本文介绍了为什么这个Java方法似乎有两种返回类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

其中 Foo 是我自己的班级。

where Foo is my own class.

此方法的返回类型是什么?为什么它似乎有两种返回类型?

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

推荐答案

不,你没有两种返回类型。它是一个 通用方法

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

你的方法可以有一个泛型 E 这是 Foo 的子类。您的退货类型是列表< Foo或任何FOO的子类型>

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>

这篇关于为什么这个Java方法似乎有两种返回类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆