Forum Stats

  • 3,815,605 Users
  • 2,259,059 Discussions


getInstance method

edited Mar 26, 2018 8:22AM in Java Card

I would like to know if the following classes are singleton.

I have to create always a new object with the getInstance method????

Thanks in advance.


  • PhHein
    PhHein Member, Moderator Posts: 7,228 Silver Trophy
    edited Mar 23, 2018 5:03AM


    have a look at the API docs:

    MesageDigest, for example, only has a protected construstor. In that case getInstance(...) is your only chance.

  • patrick.vh-Oracle
    patrick.vh-Oracle Member Posts: 18 Employee
    edited Mar 26, 2018 8:22AM


    These classes are not singleton for several reasons:
    - these are stateful classes that contain the current state of an on-going operation. In particular, the update() method may accumulate data in an internal buffer before processing it.
    - several application on the platform may need to perform the same operation at the same time so each need to use its own independent instance.

    However, an application can get an instance and store it in a persistent field (e.g. in the Applet.install() method) then re-use it several times (e.g. in Applet.process() method)


This discussion has been closed.