T
tomjbr.10216233
Is it even possible to correctly implement a method with the signature
below ?
"public static boolean isMutable(Class c)"
This method should be able to use reflection to detect if an arbitrary
class is mutable, i.e. if the fields in the class are ever changed
outside of the constructor.
I know that you can quite easily programmatically detect if all the
fields are final and if so, you can jump to the conclusion that the
class is immutable, but a class could of course be immutable even if
the fields are not declared as final.
I think Aspect-Oriented Programming (AOP) could be used to
programmatically detect when a field _is_ changed, but the question
here is whether it is possible to detect that a field _can_ be changed.
If it is actually possible, maybe there exists an open source class
with an implementation of the method I am looking for ?
/ Tom
below ?
"public static boolean isMutable(Class c)"
This method should be able to use reflection to detect if an arbitrary
class is mutable, i.e. if the fields in the class are ever changed
outside of the constructor.
I know that you can quite easily programmatically detect if all the
fields are final and if so, you can jump to the conclusion that the
class is immutable, but a class could of course be immutable even if
the fields are not declared as final.
I think Aspect-Oriented Programming (AOP) could be used to
programmatically detect when a field _is_ changed, but the question
here is whether it is possible to detect that a field _can_ be changed.
If it is actually possible, maybe there exists an open source class
with an implementation of the method I am looking for ?
/ Tom