Showing posts with label restrictions. Show all posts
Showing posts with label restrictions. Show all posts

Saturday, 28 May 2011

Restrictions on clone method

There are couple of restrictions on clone methods:
  • It is a protected method and can only be called from within the same class or the module that contains the class.
  • We can only clone objects which are declared to implement the Cloneable interface.
  • Objects that cannot be cloned throw the CloneNotSupportedException.

Wednesday, 27 April 2011

Restrictions on annotations

  1. No annotation can inherit another.
  2. All methods declared by an annotation must be without parameters.
  3. Annotations cannot be generic.
  4. They cannot specify a throws clause.
Also they are allowed to return only :
  • primitives
  • String
  • Class
  • enum
  • array of the above types

Tuesday, 12 April 2011

Restrictions on enum types

Though enum types are full-fledged classes, the following are not allowed with enums:

  • enums cannot be subclassed
  • enums cannot have public constructor
  • enums are not allowed to be instantiated (using new)
  • enums cannot be cloned

All of these are enforced during compile-time.