views:

80

answers:

3

why does hibernate not force you to mark fields as virtual, but nhibernate does?

Is this a result of the differences between the VM and CLR?

+2  A: 

In Java all methods are by default virtual. In .NET you need to explicitly mark a method as virtual.

kgiannakakis
+1  A: 

Because the default behaviour in Java is for methods to be overridable unless the final keyword is specified, whereas in .NET it is for methods to be non-overridable unless the virtual keyword is specified.

David M
Not fields - fields can't be overridden at all in either environment.
Jon Skeet
+5  A: 

This isn't a difference between runtimes - it's a difference between languages.

In C#, methods aren't virtual by default. In Java, they are.

Note that neither platform allows fields to be virtual, as described in your question.

Hibernate and NHibernate both require virtual methods - which means making them explicitly virtual in C#.

(Note that in Java the terminology "virtual method" isn't actually defined in the language specification; here I'm using it to mean "non-final": a method which can be overridden.)

Jon Skeet
I am a java guy and that sound extremly strange to me. Nevertheless...
Willi
@Willi: Which bit sounds extremely strange?
Jon Skeet