Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Create a generic method `calculateSum` that takes a list of numbers and returns the sum */
- void main() {
- var a = One();
- print(a.calculateSum([1,2,3,4,5]));
- }
- class One
- {
- One();
- T calculateSum<T extends num>(List<T> list1)
- {
- num sum1=0;
- for(var element in list1)
- {
- sum1=(element+sum1);
- }
- return sum1 as T;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement