今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Interface constraints
- [Narrator] When we introduced interfaces previously, we talked about them in terms of methods. Meaning that any type that had all the methods of the interface was set to implement that interface. Interfaces can also include a type set meaning you can declare the set of types that satisfied, not just methods. Recall our generic sum function from earlier. We'll extract the type list from a signature and move that into its own interface. That's chapter nine seven and we'll decline a type, numeric, making data interface. We will now move the type information into that interface and now I'll make T of type numeric. The added benefit here is that numeric is an interface like any other we are accustomed to and go. We can add a method to it and require that any value of type numeric also have that method. Now we can run our program again and voila. Interface constraints are likely to see a lot of usage in your own code, and the…