[Mono-bugs] [Bug 29590][Nor] Changed - Access of private constructor possible
bugzilla-daemon@rocky.ximian.com
bugzilla-daemon@rocky.ximian.com
30 Aug 2002 01:21:22 -0000
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by gonzalo@ximian.com.
http://bugzilla.ximian.com/show_bug.cgi?id=29590
--- shadow/29590 Wed Aug 28 17:11:39 2002
+++ shadow/29590.tmp.11844 Thu Aug 29 21:21:22 2002
@@ -1,22 +1,21 @@
Bug#: 29590
Product: Mono/MCS
Version: unspecified
OS: SuSE 8.0
OS Details:
-Status: NEW
-Resolution:
-Severity:
+Status: RESOLVED
+Resolution: NOTABUG
+Severity: Unknown
Priority: Normal
Component: Misc
AssignedTo: mono-bugs@ximian.com
ReportedBy: ritterfelix@web.de
QAContact: mono-bugs@ximian.com
TargetMilestone: ---
URL:
-Cc:
Summary: Access of private constructor possible
It is possible to create an object using "new" if the constructor is
private.
Example:
@@ -30,6 +29,47 @@
return instance;
}
}
...
Singleton a = new Singleton(); // it works, but it should not
+
+------- Additional Comments From gonzalo@ximian.com 2002-08-29 21:21 -------
+Try this:
+class Singleton
+{
+ public static Singleton instance=null;
+ private Singleton() {
+ }
+ public static Singleton getInstance() {
+ if (instance==null) instance = new Singleton();
+ return instance;
+ }
+
+}
+
+class C
+{
+ static void Main ()
+ {
+ Singleton s = new Singleton ();
+ }
+}
+
+instead of:
+class Singleton
+{
+ public static Singleton instance=null;
+ private Singleton() {
+ }
+ public static Singleton getInstance() {
+ if (instance==null) instance = new Singleton();
+ return instance;
+ }
+ static void Main ()
+ {
+ Singleton s = new Singleton ();
+ }
+
+}
+
+;-)