.net 中用Obsolete属性,每次使用被标记为已过时的实体时,随后将生成警告或错误,这取决于属性是如何配置的。

c#:

[System.Obsolete("use class B")]class A{ public void Method() { }}class B{ [System.Obsolete("use NewMethod", true)] public void OldMethod() { } public void NewMethod() { }}// Generates 2 warnings:A a = new A();// Generate no errors or warnings:B b = new B();b.NewMethod();// Generates an error, terminating compilation:b.OldMethod();

为类 A 产生两个警告:一个用于声明类引用,一个用于类构造函数。


vb.net:

<System.Obsolete("use class B")> Class A Sub Method() End Sub End Class Class B <System.Obsolete("use NewMethod", True)> Sub OldMethod() End Sub Sub NewMethod() End Sub End Class' Generates 2 warnings:' Dim a As New A' Generate no errors or warnings:Dim b As New Bb.NewMethod()' Generates an error, terminating compilation:' b.OldMethod()


java中使用@Deprecated注解,标记已过时.

@Deprecatedpublic void showTaste(){ System.out.println("水果的苹果的口感是:脆甜");}