top | item 44675605

(no title)

buerkle | 7 months ago

But then you are representing two distinct types as the same underlying type, String.

  MyType extends String;
  void foo(String s);
  foo(new MyType()); // is valid
Leading to the original problem. I don't want to represent MyType as a String because it's not.

discuss

order

qcnguy|7 months ago

It has to work that way or else you can't use the standard library. What you want to block is not:

    StringUtils.trim(String foo);
but

    myApp.doSomething(AnotherMyType amt);
The latter is saying "I need not any string but a specific kind of string".

buerkle|7 months ago

No I want to block both. I don't want to give devs the option of creating a function doSomething(String) that happens to accept MyType. If I need to call trim then I'll do

  StringUtils.trim(MyType.toString());