J#(Java's) scoping rules are a bit different from that of other languages
in .net - A Java protected member means, it can be accessible from the
derived classes or from anyone in the same package. The J# compiler
implements this rule by making the member as public, but also marks this
member with a flag which only the J# compiler(and also the Java reflection
engine) understands. So in this present scenario, if you use Java
reflection(java.lang.reflect) you would get the proper results.
If you want to use .net Reflection as you have done below, then compile the
assembly using "/ss" (secure scoping) option of the compiler - if you use
this option the J# compiler will make the protected member as
familyOrAssembly. For details on secure scoping please read on the
following link
http://msdn.microsoft.com/library/de...us/dv_vjsample
/html/vjsamscopingsampleusingsecurescoping.asp
Thanks,
Diganta Roy
Microsoft Visual J# .NET Product Team
This posting is provided "AS IS" with no warranties, and confers no
rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
--------------------
Quote:
Thread-Topic: get_IsPublic ()and get_IsFamily ()property returns wrong
value .Please help
thread-index: AcQsM2DUoTBHTE7rR8eQX00OnIXwOw==
X-WN-Post: microsoft.public.dotnet.vjsharp
From: "=?Utf-8?B?U2FtaWRoYQ==?=" <anonymous (AT) discussions (DOT) microsoft.com
Subject: get_IsPublic ()and get_IsFamily ()property returns wrong value
Please help
Date: Tue, 27 Apr 2004 01:41:05 -0700
Lines: 32
Message-ID: <E8C75841-530D-4116-907D-2633E2A71E19 (AT) microsoft (DOT) com
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Newsgroups: microsoft.public.dotnet.vjsharp
Path: cpmsftngxa10.phx.gbl
Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.vjsharp:5961
NNTP-Posting-Host: tk2msftcmty1.phx.gbl 10.40.1.180
X-Tomcat-NG: microsoft.public.dotnet.vjsharp
Hi,
get_IsPublic() property returns true if this field is public;
|
otherwise, false and get_IsFamily() propety returns true if the field has
the Family attribute set; otherwise, false.But in the following code it
returns true and false repectively whether it is declared as protected in
J# Can you help me out .
Thanks,
The actual code is as follows
import System.*;
import System.Reflection.*;
public class FieldInfoClass
{
public int myField1 = 0;
protected String myField2 = null;
public static void main(String[] args)
{
FieldInfo myFieldInfo[];
Type myType = FieldInfoClass.class.ToType();
// Get the type and fields of FieldInfoClass.
myFieldInfo = myType.GetFields((BindingFlags.NonPublic |
BindingFlags.Instance | BindingFlags.Public));
Console.WriteLine("\nThe fields of " + "FieldInfoClass are \n");
// Display the field information of FieldInfoClass.
for (int i = 0; i < myFieldInfo.length; i++) {
Console.WriteLine("\nName : {0}",
myFieldInfo[i].get_Name());
Console.WriteLine("Declaring Type : {0}",
myFieldInfo[i].get_DeclaringType());
Console.WriteLine("IsPublic : {0}",
System.Convert.ToString(myFieldInfo[i].get_IsPublic()));
Console.WriteLine("MemberType : {0}",
myFieldInfo[i].get_MemberType());
Console.WriteLine("FieldType : {0}",
myFieldInfo[i].get_FieldType());
Console.WriteLine("IsFamily : {0}",
System.Convert.ToString(myFieldInfo[i].get_IsFamily()));
}
} //main
} //FieldInfoClass