将类型限制为Int,Double,long的泛型 [英] Generics that restricts the types to Int, Double, long

查看:46
本文介绍了将类型限制为Int,Double,long的泛型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以约束一个方法,使其仅接收 int double long 或其他具有常规数值的数值类型

Is it possible to constraint a method so that it receives only int, double, long or other numerical types that has the usual numerical operations ( such as +,-,*,/) defined?

推荐答案

当前无法实现.

此外,请参见此问题以获取可能的解决方法

Also, see this question for a possible workaround

这篇关于将类型限制为Int,Double,long的泛型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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