Thursday 15 July 2010

c# - What is the practical use of extension methods in Java? -


I understand the C # extension methods, in which they allow to add new methods to the definition of a previously closed class Give. Java Defender / Extension methods are completely separated, for example:

  Public Interface Interfaceable {Public Zero Regular (); Public Default Zero Defender () {System.out.println ("I'm Safe"); }; OK, so I think you can do 'specialty-y' things with Java extension methods, but I do not know that it's the only thing (an "extension" Is called) why not? If that sounds like, do not talk about it, can someone help me?   

These reasons were added to Java, so there is an easy upgrade path for things like archiving classes. The challenge with the addition of Closer is that you now have lots of functions that you want to add to the standard collection. However, if you add them to the existing interface, then you break any implementation of those interfaces. Around it in a new way is to add an additional interface. It is possible without virtual expansion methods, however, it has its own drawbacks, that is, it can be used before implementing that new interface. Since there are several implementations there, it can take a lot of time to upgrade all those implementations. However, the way you want to add at the same time, they are very agnostic for implementation. They should basically do the same thing on a basic basis, at least The way the team decided to handle this matter, it enabled the specification of the default behavior, which can be overridden. Apart from the interface, this kind of functionality is present and it depends on the author of the library that they want to write a different implementation. The key is that they do not have to do this, or by the time they do not do this, there is a gap gap in the functionality of the interval.

It is very low, they basically act like symptoms and you are right that they are not the same thing as the extension methods in C #. I have read the original implementation of it, since C # is more, however, because of the limitations of style (i.e. unable to override functionality) due to the decision to use them and the lack of being able to use reflection they find that It seems that the name has been stuck, even if the approach of implementation has changed.

See virtual expansion methods explained for full details.

No comments:

Post a Comment