要求泛型类型不使用Object类的默认equals和hashCode方法

时间:2016-01-20 00:57:53

标签: java

我们说我有一些课

$img = $_POST['data'];
$img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$fileData = base64_decode($img);
//saving
$fileName = 'photo.png';
file_put_contents($fileName, $fileData);

我能以某种方式要求public class SomeClass<T> { public SomeClass() { //or throw exception here if T is not an interface but this is not preferred. } } Tequals覆盖hashCode的实施吗?我能想到的一种方法是使用这样的东西:

Object

但我确实想使用抽象类方法,因为我不能使用任何扩展其他类的类(没有多重继承,并且使用包装器只会添加更多的样板)。

对于例外路线,我可以使用一些东西 How to check if a class has overridden equals and hashCodehttps://stackoverflow.com/a/13974262/5130921

0 个答案:

没有答案