Question: JAVA - - - Consider this code a.method( b.expensive(c) ); where a is an instance of Aclass which has a method called method() that rarely

JAVA - - - Consider this code a.method( b.expensive(c) ); where a is an instance of Aclass which has a method called method() that rarely uses its parameter. The object b is an instance of Bclass which has a very expensive method called expensive; this method takes one parameter of class Cclass and returns a value of class Eclass.

The declaration for method() begins method(Eclass e). Later, it contains the code if(unlikely)use(e); where use() is some other method in the same class.

a) You could just rewrite method() so that it is called as a.method(b, c); passing the parameters b and c without evaluating expensive(), thus avoiding wasted computation. Assume this rewrite and give the declaration for the parameters to method() and the new version of the code in the if(unlikely) statement.

b) The above solution to avoiding wasted computation could create problems. Demonstrate the difficulties this would create by describing at least one legal calls to method() that would be difficult to rewrite to take advantage of the rewritten version of method() from part a.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!