简体   繁体   English

无法理解复杂的参数化返回类型-Java

[英]Not able to understand a complex parameterized return type - Java

I have come across a snippet similar to this in Java 我遇到了一个类似于Java的代码段

public <H extends ABC<I, U>, I, U> Set<U> get(Type<H, I, U> type) {

}

I do not understand this. 我不明白这个。 I only understand that it takes a parameter of the parameterized type Type<H,I,U> and that it returns a Set<U> which is the return type. 我只了解它接受参数化类型Type<H,I,U>的参数,并且返回Set<U>这是返回类型。 But, I do not understand the part: 但是,我不了解该部分:

<H extends ABC<I,U>, I,U>

Can anybody clarify it? 有人可以澄清吗?

Regards, Chetan 问候,车丹

It means that 这意味着

  • The method takes three type parameters: H , I , and U 该方法采用三个类型参数: HIU
  • I and U can be anything IU可以是任何东西
  • H must extend ABC<I, U> (or it can actually be ABC<I, U> ) H必须扩展ABC<I, U> (或者实际上可以是 ABC<I, U>

So presumably you have a type ABC which has two type parameters. 因此,假设您有一个具有两个类型参数的ABC类型。 This is saying that, for instance, this would be valid: 这就是说,例如,这将是有效的:

Type<ABC<String, Date>, String, Date> type = new Type<>();
Set<String> set = instance.get(type);

...because there H would be ABC<String, Date> , I would be String , and U would be Date . ...因为H将是ABC<String, Date>I将是String ,而U将是Date

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM