C# FAQ: What are the differences between CSharp and Java reflection
Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio
| CSharp-Online.NET:FAQs |
| edit |
What are the differences between C# and Java reflection?
Reflection is the ability to discover the members of a class and to invoke methods at runtime. Both the Java and C# languages support reflection.
The primary difference between them is that C# reflection is performed at the assembly level while Java reflection is performed at the class level. Typically, assemblies are stored as .DLL files. Whereas C# must have access to the DLL in question, Java must be able to load the class file in question.
The Java Reflection API is a bit higher level than the C# Reflection API. For example, C# has a ParameterInfo class containing metadata about Method parameters, while the Java system uses Class objects which do not return some information details like the parameter name.
Class metadata can be encapsulated as an object. In C#, use GetType() to encapsulate into a System.Type object as in the following example:
// C# example Type type = typeof (ArrayList);
In the Java language, use getClass() to encapsulate into a java.lang.Class object as in the following example:
// Java example: append ".class" to the class name Class class = java.util.Arraylist.class;