Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Empty constructor in FeedReaderContract demo

Tags:

java

android

Referring to the FeedReaderContract class on Android Developers page:

  • Saving Data in SQL Databases

The code starts as:

public final class FeedReaderContract {
    // To prevent someone from accidentally instantiating the contract class,
    // give it an empty constructor.
    public FeedReaderContract() {}

i.e. there is a default public constructor for the class.

  • Is that code comment correct?
  • How does a public empty constructor prevent instantiation - should this maybe be private?

... am I still half asleep ? ...


PS I'm not concerned about the rest of the example, or how to use it. I am purely trying to confirm that I'm not going mad and stupid at the same time...

like image 230
Richard Le Mesurier Avatar asked Dec 04 '13 10:12

Richard Le Mesurier


1 Answers

Self answer because this may help beginners?

The code comment is wrong. Empty constructor works fine.

To prevent instantiation, the constructor needs to be private, not empty.

like image 181
Richard Le Mesurier Avatar answered Sep 27 '22 21:09

Richard Le Mesurier