"Private Constructors" - What's that for?

I read a sentence from a book, saying that "Suppose that you want to create a class but you don't want it to be instantiated as an object. Just declear the class's constructors as private."
It's out of my imagination. What's the real user case for this weird "Private Consturctor"? Who knows?
Thanks.
CL

public class TestFact {
  private TestFact() {}
  public static TestFact makeTestFact(String s) {
    if ("Dog".equals(s)) {
      return new Dog();
    if ("Cat".equals(s)) {
      return new Cat();
    return null;
  protected String whatever() {
    return "foo";
  private static class Dog extends TestFact {
    public String toString() {
      return whatever() + " dog";
  private static class Cat extends TestFact { }
}I must be really bored at work today...

Similar Messages

  • Hi, I am in Winnipeg, MB.  I don't know why they kept sending me a via email about the billing....what's that for?  Carol.

    Hi I am from Winnipeg, MB.  I don't know why they kept sending me an email about the billing so what's that for?  Please help me.  Thanks, Carol

    If they are asking for credit card information it's a scam, not Apple.

  • To the left are 3 balls, red, yello, green, that go around in a circle. when i click on them it says download helper, what is that for and how do I learn more about them?

    to the left of the URL are 3 balls, red, yellow, green, that go around in a circle. when i click on them it says download helper, what is that for and how do I learn more about them?

    Thanks, this is very helpful, and resolved my question
    dan

  • Whenever I try to login to my instagram an error appears saying that they couldn't connect to their login server ... What is that for? And how to fix that?

    Whenever I try to login to my instagram an error appears saying that they couldn't connect to their login server ... What is that for? And how to fix that?

    I called Apple Support and they walked me through it. They told me to basically copy and paste my music to the external hard drive. (I think.) Or maybe it was they had me transfer a folder to the EHD. I don't exactally remember it was a few years back. But I tried to plug in the EHD before starting and...nothing. Still says same thing, "locate file."

  • New control attribute in screen painter: switch , what's that for?

    Hi, gurus
    i noticed that in the screen painter, there is a new , maybe two , control attribute, called siwtch, or switch frame work, could you pls tell me what' s that for?
    br.
    jun

    Hi,
    Pls check this link it will very helpful for u.
    http://thespot4sap.com/Articles/SAP_Design_Example_Transaction_Code.asp
    Thanks,
    Shankar

  • HT201210 my error number was -1, what's that for?

    my iphone kept saying it needed to restore, so I went to restore it in Itunes, and I got an error number -1 which isn't listed with the other numbers. what does that one mean?

    Error -1 generally means a catastrophic hardware failure.  You'll need to bring your phone into Apple or the authorized service provider in your country.

  • I was just prompted (out of no where) that "CoreServicesUiAgent" would like to access your calendar. Don't Allow. Allow. - What's that for? Why did it show up and do I allow or not? I've googled this extensively and no one knows what it is. Thanks.

    This promt seems to relate to iCal - it is requesting access to my "calendar" but the icon shows the iCal icon infront of some icon of a house with a dial - maybe it is supposed to look like a safe dial protecting my house.
    There is a ? that launches the Help Centre. There is says the prompt is because something is tying to access the calendar and I need to give permission but I'm not running anything that would have needed access.
    Is it possible that one of the websites I was on prompted it? I didn't download anything - but I'm working in SmartSheet, which uses a calendar tool to track projects. Any chance that's trying to communicate with iCal in the background?
    But I can't see anywhere online where people know what the CoreServicesUIAgent is, and there's no more info about what/who I'd be giving access to my calendar.
    Help?
    Thanks,
    k

    Thanks, I'd done that before coming to Apple and didn't receive any additional information about whether it's safe to choose "Don't Allow" or "OK". I don't know what I'm in for if I choose either one. Can't afford to lose that calendar. I depend on it too much.

  • Data upload few times a day?what's that for ?

    I recently bought a iphone 3GS from Apple and began using it , I seldom go on the net using my iphone and i switch off my 3GS connection most of the time .I only use WIFI when I'm at home using my home wireless internet . I did not activate the mail account as I don;t want my emails to be diverted to my phone as it will cost me since I do not subscribe to a package data.I received a sms from my service provider that I my bill has exceeded 4 months of my regular bill which was shocking to me as I rarely surf the net using my phone , I noticed from my bill that there are daily data package being sent into my phone sometimes a few times a day even at the time when I'm asleep and not using the phone .What is this data packages that is sent to the phone.this is very distressing.can some one help to tell me how can I stop this as my bill is so much that I can buy another iphone .

    Turning off 3G does not turn off data connections either. It does turn off high speed cellular data, but EDGE can handle data too (it just can't simultaneously handle voice and data traffic). If you have location services enabled, that will also use data (and not just to get maps if using the Maps app, but also to get/receive data from cell towers for triangulation), as will weather apps, newspaper readers, RSS feeds, and other apps that, when launched, need to go out and update their data stream.
    About the only way you can be sure to never use data is to put your iPhone in airplane mode - which pretty much defeats the purpose of even having a smart phone. Really, the best solution is get a data plan. Or sell your iPhone for an iPod touch and a very basic voice-call only cellular phone.

  • There is a metal circle that goes under my home button. What is that for? How do i properly place the home button on the iPod Touch?

    I need help!!

    It's possible that Fiona doesn't know what you mean. I don't.
    However, I wonder if you mean the small circle (that isn't metal) at the top of the screen.
    That's a camera.
    The only thing at the bottom of the iPod is the Home button - there's nothing underneath it. You can see in the picture, a recessed circle with a printed grey square inside it - the Home button.
    (I have noticed that pictures of the 2nd gen Touch - which I own - do not show the small (also not metal) circle at the top left above the screen. It's a light sensor.)
    So if your iPod does not look exactly like the one in the picture, can you post a picture of yours, with this small metal circle thing too?

  • Patch 5251025: what is that for ?

    Dear Experts,
    I can see there are:
    - patch 5251025 for Oracle 10.2.0.2
    - and patch 5239698 for Oracle 10.2.0.1.
    But to me the last release of Oracle Database 10g is 10.2.0.1.0 (available from site) so what is the 10.2.0.2 patch for ?
    Best Regards,
    Guillaume

    Both patches are Critical Patch Updates, the first one for DB Version 10.1.0.2 (already patched with the first patchset) and the second one for DB Version 10.1.0.1 (base release).
    Werner

  • Icon with small lock in clockwise arrowe on my iphone 5s screen , what is thats for?

    i have small unknown icon on my iphone 5s, small clockwise circle with locke simbole , what is that

    That would be rotation lock.
    http://support.apple.com/kb/ts3805

  • Dont understand the sound bloo bloob bloo, what is that for?

    While I use my mac air it makes weird sound like "bloo bloob bloo" randomly, I cant find any reason and its not in system sounds

    The only way to figure this out is by a process of elimination.
    Log out and log back in. Don't launch any applications. If you get the sound, it's probably caused by one of your login items. Eliminate them until you find the culprit. Less likely, it might be an alert sound caused by a LaunchAgent or some system-level process, but I doubt that.
    If you don't get the sound right after logging in, it's caused by one of the applications you launch yourself.

  • Getting Private Constructor of a Class

    Hello all,
    Is there any way to get the private constructor as we get the public constructors using Class.getConstructors() ?
    getConstructors() method is not returning the private constructors, but I need the info about the private constructors also....so if it is possible, please let me know...
    Thanks

    tullio0106 wrote:
    I know, however it's also impossible to invoke private methods but, using reflection, You can.That's a complete different thing. If the private method is not static, it is invoked on the current instance.
    Is it also possible to use private constructors in the same way.
    The problem I'm facing is to create a new instance of a class which extends another class and I need to use a private constructor of the superclass (I've no sources of that superclass).First, the Constructor of a class has to invoke a Constructor of a superclass as the first operation (either implicitely invoking an empty constructor or explicitely). There is no way to do any other operation before that. Second, a reflectively fetched Constructor instance always only can create instances of the class it is defined at (using newInstance()). So, yes, you could get access to a private Constructor. With that, you may be able to create a new instance of the class it is defined for. But that's about it.

  • What is that little whole next to the Cd/dvd drive in macbook pro?

    what is this for?
    on the right side of the macbook pro has a Cd/Dvd drive and a little dot. a whole actually. what is that for?

    It is bigger than a dot, true, but on my MBP (2011) it's on the right-hand side next to the optical drive, and I have no tiny dot for ejecting the drive with a paperclip!  Mine looks like this:

  • Why is it that AS3 does not support private constructors as AS2 does?

    Why is it that AS3 does not support private constructors as
    AS2 does?
    Private constructors are standard in most OOP languages (for
    example
    C++ and Java) and were supported in Actionscript 2. However,
    this is
    not the case in AS3 which only allows its constructors to
    have the
    'public' access modifier.
    I have legacy code that I hope to migrate to the AS3
    platform. Some
    key elements of my code rely on design patterns like the
    Singleton
    pattern which in turn depend on private constructors. I could
    refactor
    my code but, ultimately, I would lose the benefits of the
    pattern
    (ie. one and only one instance of the Singleton class).
    I have also used private constructors to simulate enumerated
    types
    much like the enums you would find in Java 5 and up. But I
    can't
    use the same implementation in AS3 without private
    constructors.
    I do not want to resort to mixing legacy code with new AS3
    code to
    keep functionality intact. Are there any possible
    work-arounds for
    this issue?
    If not, are there any lobbying groups I need to know about so
    that
    we can get this feature back?

    http://www.gskinner.com/blog/archives/2006/07/as3_singletons.html

Maybe you are looking for

  • Pop up effect on thumbnail

    is it possible or how can you create an pop up effect when hovering the thumbnail for a slide show? enable the pop up while hovering the thumbnail rather than clicking on it so when you place your curse on top of a thumbnail it shows the full picture

  • I have problem login to you tube built in

    I have problem login to youtube built in in ipad1 3.2 upgraded to 5.1.1, it simply do not get in rather in pc logged in without problems well? may install new you tube app not built in but stand alone or it can not done?

  • Clip info lost on import

    I'm shooting XDCAM EX 720p50 footage with EX1R. I've been trimming the inevitable rubbish from the beginning and end of my clips as well as adding notes and changing the Index Picture with Sony Clip Browser but when I import to FCP with Log and Trans

  • HT204370 I have purchased movie hunger games but unable to download on my iPad 2. All of sudden it show error sigh and says not enough place?

    2 days back I purchased movie hunger games on my iPad 2 32g  and I paid and got the reciept ,when I tried to tap to download it shows error sign and says 'delete pictures and videos ... To start I barely have much stored still I took my pictures and

  • Recovering 'Mysafe' folder from infected HDD in Ubuntu

    Hi, my wife's laptop was hit pretty hard by 'protectmypc' virus. went bsod on me. followed howtogeek.com img iso brnt ubuntu to run and recoeverd most of my files. Now before i do a clean install, i can't recover anything in the mysafe folder.... How