The only method signatures that Ref and Ref.View have in common are those inherited from AnyRef. This implies that if we are careful in our definition of equals we can use the same instance for both the reference and the single-operation view! This would avoid any object creation overhead for the use of .single.
Direct use of the concrete instances such as TIntRef would no longer be convenient, because an ambiguity would be created. When typecast to either a Ref[Int] or Ref.View[Int], however, things would work fine.
Is this clever or evil?
The only method signatures that
RefandRef.Viewhave in common are those inherited fromAnyRef. This implies that if we are careful in our definition ofequalswe can use the same instance for both the reference and the single-operation view! This would avoid any object creation overhead for the use of.single.Direct use of the concrete instances such as
TIntRefwould no longer be convenient, because an ambiguity would be created. When typecast to either aRef[Int]orRef.View[Int], however, things would work fine.Is this clever or evil?