COMP204-07B Assignment 6
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
line argument).
- 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 maximum integer value 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 [0..max]. Method calls outside that range
will throw some Exception.
-
Print out this maximum valid integer value.
-
Print out the return for calling Method with this maximum integer value.
Assuming that some binary file a6_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 A6 a6_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
Max = 9
return value for max = 9
Assuming that some binary file a6_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 A6 a6_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:
- Functionality
- 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.