diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-06-04 16:13:59 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-06-04 16:13:59 +0100 |
| commit | 117e22cdd0d6b20968fc39e2c8e1a7e6c73e9e73 (patch) | |
| tree | 0d1d5fedf73a322b9f72ff6593739f0188714f2c /Mammoth/Couscous/java/util | |
| parent | f5a729ceda45b534c7cc709097cf6d115afa52fa (diff) | |
Use single instance of None
Diffstat (limited to 'Mammoth/Couscous/java/util')
| -rw-r--r-- | Mammoth/Couscous/java/util/HashMap.cs | 2 | ||||
| -rw-r--r-- | Mammoth/Couscous/java/util/Optional.cs | 7 |
2 files changed, 7 insertions, 2 deletions
diff --git a/Mammoth/Couscous/java/util/HashMap.cs b/Mammoth/Couscous/java/util/HashMap.cs index 38e516e..10070fc 100644 --- a/Mammoth/Couscous/java/util/HashMap.cs +++ b/Mammoth/Couscous/java/util/HashMap.cs @@ -30,7 +30,7 @@ namespace Mammoth.Couscous.java.util { if (_dictionary.ContainsKey(key)) { return new Some<TValue>(_dictionary[key]); } else { - return new None<TValue>(); + return None<TValue>.Instance; } } diff --git a/Mammoth/Couscous/java/util/Optional.cs b/Mammoth/Couscous/java/util/Optional.cs index f295688..b5be056 100644 --- a/Mammoth/Couscous/java/util/Optional.cs +++ b/Mammoth/Couscous/java/util/Optional.cs @@ -16,6 +16,11 @@ namespace Mammoth.Couscous.java.util } internal class None<T> : Optional<T> { + internal static readonly None<T> Instance = new None<T>(); + + private None() { + } + public bool isPresent() { return false; } @@ -92,7 +97,7 @@ namespace Mammoth.Couscous.java.util { internal static Optional<T> empty<T>() { - return new None<T>(); + return None<T>.Instance; } internal static Optional<T> of<T>(T value) |
