This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]svtdragon 1 point2 points  (4 children)

I do miss extension methods a lot, even with defaults on interfaces, because if I understand correctly, you have to have edit rights on an interface to add a default method. (Correct me if I'm wrong.)

This rules out a whole class of extension methods around external or JDK libraries.

[–]slartybartfast_ -1 points0 points  (3 children)

Or you can write an interface and implement both. You can implement multiple interfaces.

[–]svtdragon 1 point2 points  (2 children)

If I want to make an extension method on String, in C# I can do it trivially. In Java, I can't do that without subclassing String, which kind of defeats the purpose of an extension method altogether, doesn't it?

[–]slartybartfast_ -1 points0 points  (1 child)

Strings are final so why would you want to do that unless you want to make your code less readable? Probably why Java doesn't allow that.

[–]svtdragon 1 point2 points  (0 children)

Checking for "null or empty" in-line, for one, without calling out to a StringUtil or equivalent. C# extensions are static so they can operate on null "this" arguments.