通用方法调用的Java类型提示 [英] Java Type Hints on Generic Method Calling

查看:107
本文介绍了通用方法调用的Java类型提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  public static< 

; T1,T2> Map< Map T1,Set< T2>>聚合(列表< Map< String,Object>>列表,字符串colK,字符串colV)
{
...
}
pre>

由于某种原因,我很想这样称呼它

  Map< String,Set< Integer>> map = aggregate< String,Integer>(lData,id,ref); 

但它没有编译,除非我将它改为

 地图< String,Set< Integer>> map = aggregate(lData,id,ref); 

我只是想知道为什么它不需要右侧的提示。而是给了我编译错误。它表示,在右边的提示之后,它预计会有一个分号。第二个是调用该方法的正确方法吗?请问有人能给我一些提示吗?

正如所示这里,调用方法的方法是:

  ClassName。< String,Integer> aggregate(lData,id,ref); 

其中 ClassName 是类的名称该方法包含在。


I'm wondering what is the proper way to call a static method with a signature like this:

public static <T1, T2> Map<Map T1, Set<T2>> aggregate(List<Map<String, Object>> list, String colK, String colV)
{
    ...
}

I was tempted to call it like this for some reason

Map<String, Set<Integer>> map = aggregate<String, Integer>(lData, "id", "ref");

but it didn't compile unless I changed it to

Map<String, Set<Integer>> map = aggregate(lData, "id", "ref");

I'm just wondering why it didn't need the hints on the right hand side. And instead gave me compilation error. It says it expects a semi-colon after the hints on the right hand side. Is the second one a proper way to call the method? Could somebody shed me some light please?

解决方案

As shown here, the way to call the method would be:

ClassName.<String, Integer>aggregate(lData, "id", "ref");

where ClassName is the name of the class that the method is contained in.

这篇关于通用方法调用的Java类型提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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