5
A
回答
5
为了使它安全,我会想。 Equals()
将一个对象作为参数,因此如果您传入错误类型的对象直到您运行它,您将看不到错误。
3
其中一个原因是,您可以要求班级与所需类型相等,而不一定是该类型。例如。
public void MyClass<T> where T : IEquatable<Foo>
{
private static readonly Foo SpecialFoo = Foo.SpecialFoo;
public void MyMethodThatProcessesTs(T theT)
{
if (theT.Equals(SpecialFoo))
{
// process theT.
}
}
}
3
除了@Bala R说什么之外,它还避免了在结构之间进行自定义相等性检查时的装箱。
相关问题
- 1. java.lang.reflect.InvocationTargetException:这是什么原因?
- 2. 这是什么原因为stackoverflow异常?
- 3. 为什么jQuery被称为jQuery?名称的原因是什么?
- 4. 为什么JSONObject无序?这背后的原因是什么?
- 5. 这个输出的原因是什么?
- 6. 这个nullPointerException的原因是什么?
- 7. 这是什么错误的原因:
- 8. 这个NoMethodError的原因是什么?
- 9. 这是什么错误的原因
- 10. 这个错误的原因是什么?
- 11. 这次事故的原因是什么?
- 12. 是什么原因导致这比SourceGraphic
- 13. 是什么原因
- 14. 在CSS中引入了margin collapse规则的原因是什么?
- 15. 不使Core Data属性编入索引的原因是什么?
- 16. InputStream为空? openStream的原因是什么?
- 17. BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE的原因是什么?
- 18. 'System.IO.IsolatedStorage.IsolatedStorageException'的原因是什么?
- 19. RejctedExecutionException的原因是什么?
- 20. 什么是UnsatisfiedLinkError的原因?
- 21. UnsupportedClassVersionError的原因是什么?
- 22. ChangeConflictException的原因是什么?
- 23. “流”被称为FILE的历史原因是什么C
- 24. 这种奇怪的Java行为的原因是什么?
- 25. 悲伤教学这种奇怪行为的原因是什么?
- 26. 是什么原因指定为elasticsearch
- 27. PlatformID.MacOSX是什么原因?
- 28. 这是什么原因在python字典中的这个命令
- 29. HTTPS主机名错误:应该是<sub.domain.com>。这是什么原因?
- 30. 找出引起什么的原因java.security.AccessControlException
谢谢大家的帮助 – flockofcode 2011-04-20 19:08:02