COMP204-08B Assignment 3
A Reflection exercise
Your task is to implement a program, that reads in the serialized
first object found in a binary file (whose name is the first command
- Print out the class of this object.
Print out the super class of this object.
Of all the public methods available for this object, find one that
takes exactly one int parameter (the primitive type, not an Integer object) and has
a non-void return type (i.e. really returns some value). If there is no such
method, simply terminate. If there is more than one such method,
select the one whose name comes first in a lexicographical ordering.
Print out the method.
Print out the return value for calling the method with a parameter value of 0.
(we will only test with objects where 0 is a valid value).
Next, find the minimum and maximum integer values for which Method can be invoked on Object.
Again we will only test with objects, where the valid range of the int
parameter is some interval [min..max]. Method calls outside that range
will throw some Exception.
Print out these minimum and maximum valid integer values.
Print out the return values for calling Method with the minimum and the maximum integer values.
Assuming that some binary file a3_arrayList10.ser contains the serialized
version of an ArrayList with ten Integer entries 0 to 9, then the output
of a sample solution should look like (more or less) like below, because the
first method in ArrayList which has the correct signature is "get(int offset)".
> java A3 a3_arrayList10.ser
Class = java.util.ArrayList
SuperClass = java.util.AbstractList
Method = public java.lang.Object java.util.ArrayList.get(int)
return value for 0 = 0
Min = 0
return value for min = 0
Max = 9
return value for max = 9
Assuming that some binary file a3_rectangle.ser contains the serialized
version of a Rectangle, which does not have any such method, then
a sample solution should look like (more or less):
> java A3 a3_rectangle.ser
Class = java.awt.Rectangle
SuperClass = java.awt.geom.Rectangle2D
What to submit:
One java file containing all you code.
Document your code well.
Use the javadoc @author tag to give your name and ID!
As always, assessment will be based on the following criteria:
- Reasonable clarity and style of programming.
- Reasonable documentation;
Here are a few hints:
- study the slides on reflection
- the largest integer is Integer.MAX_VALUE
- if Integer.MAX_VALUE is not valid, use binary search between 0 and Integer.MAX_VALUE
to find the maximum valid integer. Similar for the minimum.