views:

126

answers:

3

In the MIDP api there is a public abstract class Layer, this class has a javadoc published however it doesn't show a constructor in the javadoc. In the same api there are two other classes Sprite and TiledLayer.

public class Sprite extends Layer
public class TiledLayer extends Layer

All these classes are in the package javax.microedition.lcdui.game

This means that the constructor of Layer has default access.

I wonder why the api of the class Layer has been published even though it cannot be sub-classed in user code?

A: 

Could it be an oversight?

Preet Sangha
It's Sun's javadoc, oversights are unacceptable there, they would have immediately released a revised version.
Kevin Boyd
+4  A: 

The public interface of Layer is published because even though you cannot extend it you can still use it when you are referencing an instance of Sprite or TiledLayer polymorphically.

In other words it is possible to treat an instance of Sprite as an instance of Layer and as such it is important to know the public interface of Layer so that you know what members are available to work with.

Andrew Hare
Makes sense! I think you hit the nail on the head. However just in case Layer was not public, what problems would it have caused to deveplopers?
Kevin Boyd
I meant to say if the javadoc of class layer wasn't published what problems would it have cause?
Kevin Boyd
No problems as far as compilation is concerned, it would just be more difficult for developers to know what was going on.
Andrew Hare
A: 

The default constructor of a class has the same visibility as the class itself. Since Layer is public, it's default constructor is public, so it can be subclassed directly.

http://java.sun.com/docs/books/jls/third%5Fedition/html/classes.html#8.8.9

Leigh
I wonder if this is the way it works, I have tried it practically and the NetBeans IDE gives the following error "Layer() is not public in .... and cannot be accessed from outside package". Evenso if a constructor is marked default it has package level access and I don't think it will be visible from outside the package.
Kevin Boyd
Old versions of JavaDoc did not document the (synthetic) default constructor. But more recent versions do. That may cause some confusion.
Tom Hawtin - tackline
@Albert: I read the article you provided in the link and it speaks of "default constructor" whereas the question in this post is about the access modifier "default" which means package level access.
Kevin Boyd