CPSC 233 Lecture 35: Generic Methods

60 views1 pages

Document Summary

You can define a generic method that has its own type parameters separate from the type parameters for the class: can also define generic methods for a non-generic class, syntax: modifiersret_type method() {} public class utility. E. g. public static double average(t[] array) double sum = 0. 0; for(int i = 0; i < array. length; i++) sum += array[i]. doublevalue(); return sum / array. length; Invoke the method by putting the concrete data type in <> just before the method name: e. g.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents

Related Questions