@@ -105,9 +105,7 @@ sealed abstract class Maybe[+A] {
105
105
final def forFailed [B >: A ](f : Failed ⇒ Maybe [B ]): Maybe [B ] =
106
106
if (isFailed) f(this .asInstanceOf [Failed ]) else this
107
107
108
- def safeCastTo [B : Manifest ]: MaybeOption [B ]
109
-
110
- def castTo [B : Manifest ]: Maybe [B ]
108
+ def castTo [B <: AnyRef : Manifest ]: Maybe [B ]
111
109
112
110
/**
113
111
* Flattens two successive maybes to one.
@@ -198,15 +196,10 @@ final case class Just[+A](get: A) extends MaybeOption[A] with MaybeEither[A] {
198
196
def filter (f : (A ) ⇒ Boolean ): Maybe [A ] = if (f(get)) this else NoVal
199
197
def foreach (f : A ⇒ Unit ) = f(get)
200
198
201
- def safeCastTo [B : Manifest ] = get match {
202
- case null ⇒ NoVal // normally null should not even be here but we are being cautious
203
- case value ⇒ if (manifest[B ].erasure.isInstance(value)) this .asInstanceOf [MaybeOption [B ]] else NoVal
204
- }
205
-
206
- def castTo [B : Manifest ] = get match {
199
+ def castTo [B <: AnyRef : Manifest ] = get match {
207
200
case null ⇒ NoVal
208
201
case value if (manifest[B ].erasure.isInstance(value)) ⇒ this .asInstanceOf [Maybe [B ]]
209
- case value ⇒ Failed (new ClassCastException (" %s -> %s" .format(get.asInstanceOf [ AnyRef ]. getClass.getName, manifest[B ])))
202
+ case value ⇒ Failed (new ClassCastException (" %s -> %s" .format(get.getClass.getName, manifest[B ].erasure.getName )))
210
203
}
211
204
212
205
def flatten1 [U ](implicit ev : A <:< Maybe [U ]): Maybe [U ] = ev(get)
@@ -240,9 +233,7 @@ case object NoVal extends MaybeOption[Nothing] {
240
233
241
234
def finallyFlatMap [B ](_finally : (Nothing ) ⇒ Unit )(f : (Nothing ) ⇒ Maybe [B ]) = this
242
235
243
- def safeCastTo [B : Manifest ]: MaybeOption [B ] = this
244
-
245
- def castTo [B : Manifest ] = this
236
+ def castTo [B <: AnyRef : Manifest ] = this
246
237
247
238
def flatten1 [U ](implicit ev : <:< [Nothing , Maybe [U ]]) = this
248
239
@@ -280,9 +271,7 @@ final case class Failed(cause: Throwable) extends MaybeEither[Nothing] {
280
271
281
272
def finallyFlatMap [B ](_finally : (Nothing ) ⇒ Unit )(f : (Nothing ) ⇒ Maybe [B ]) = this
282
273
283
- def safeCastTo [B : Manifest ]: MaybeOption [B ] = NoVal
284
-
285
- def castTo [B : Manifest ] = this
274
+ def castTo [B <: AnyRef : Manifest ] = this
286
275
287
276
def flatten1 [U ](implicit ev : <:< [Nothing , Maybe [U ]]) = this
288
277
0 commit comments