PRB: Cannot Access Static Members of Visual J# .NET Interface in Visual C# .NET or Visual Basic .NET (815253)
The information in this article applies to:
- Microsoft .NET Framework 1.1
- Microsoft .NET Framework 1.0
- Microsoft Visual C# .NET (2003)
- Microsoft Visual C# .NET (2002)
- Microsoft Visual Basic .NET (2003)
- Microsoft Visual Basic .NET (2002)
- Microsoft Visual J# .NET (2002)
- Microsoft Visual J# .NET (2003)
SYMPTOMS When you implement an interface that is declared in Visual
J# .NET and that has a static member variable in your Visual C# .NET class or
your Visual Basic .NET class, you may receive the following error message
during compilation: Visual C# .NET Error 'MyTestJSharpClassLibrary.IMyJSharpInterface' does not contain a
definition for 'MyStaticMember' Visual Basic .NET Error 'MyTestConsoleApplication.MyTestClass' must implement 'Public
Const MyStaticMember As Integer = 0' for interface
'MyTestJSharpClassLibrary.IMyJSharpInterface'. CAUSE In Microsoft Visual J# .NET, you cannot declare static
methods in an interface, but you can declare static member variables in an
interface. In Visual C# .NET and in Visual Basic .NET, you cannot declare
static members in an interface. Therefore, you cannot access the static member
of your Visual J# .NET interface.WORKAROUNDMicrosoft recommends that you not add static members in an
interface. Instead of using interfaces, use abstract classes, and declare
static members. For example, you can use the following abstract class code for
the Visual J# .NET interface in the "More Information" section: package MyTestJSharpClassLibrary;
public abstract class MyTestAbstractClass
{
public static int MyStaticMember; // Static member variable
public int NonStaticMember()
{
return 0;
}
}
STATUS This
behavior is by design.REFERENCESFor more information about Visual J#, visit the following
Microsoft Developer Network (MSDN) Web site:
Modification Type: | Major | Last Reviewed: | 8/7/2003 |
---|
Keywords: | kberrmsg kbCompiler kbJava kbprb KB815253 kbAudDeveloper |
---|
|