Convince yourself from the JavaDoc that the above is the case
At compile time, it will be necessary to tell the relationship between two types, say t1 and t2, which will always yield one of the following (the examples below are based on how normal Java would behave):
For example,
narrows(new RefType("java.lang.String"), new RefType("java.lang.Object"))
should return true.
narrows(new RefType("java.lang.Short"), new RefType("java.lang.Object"))
should return true,
even though there is java.lang.Number in between the two classes.
narrows(new RefType("java.lang.Object"), new RefType("java.lang.String"))
should return false, because Object does not narrow String
narrows(new PrimType("boolean"), new PrimType("int"))
should return false.
narrows(new PrimType("int"), new PrimType("boolean"))
should return false.
narrows(new PrimType("int"), new PrimType("int"))
should return false.
widens(new RefType("java.lang.String"), new RefType("java.lang.Object"))
should return false.
widens(new RefType("java.lang.Number"), new RefType("java.lang.Short"))
should return true.
widens(new RefType("java.lang.String"), new RefType("java.lang.Number"))
should return false.
widens(new PrimType("boolean"), new PrimType("int"))
should return false.
widens(new PrimType("int"), new PrimType("boolean"))
should return false.
widens(new PrimType("int"), new PrimType("int"))
should return false.
The HierarchyInterface is used as follows.
It is important to note that widens. and narrows must always return results consistent with the hierarchy declared at their point-of-call. However, it is possible that your implementation could run more efficiently after finished is called.
The results of your studio session are to be reported and documented in a file that you save in your workspace. You are to print and turn in one copy of that report for your group. In the descriptions of the studio exercises, verbs like report and document are indications of activities you should summarize and discuss in your report.In your groups, take turns documenting results, looking over shoulders, and staffing the keyboard.
It is unacceptable to copy anything without understanding it. At any point, the TA or instructor can point to something you've done and ask you why it works, or change it and ask what would happen with the modification.
Type lcs(Type a, Type b)in your TeamHierarchy class that uses your HierarchyInterface implementation to find the least common superclass of types a and b, and returns null if the types have no common superclass.
Talk about your approach with anybody who will listen. Demonstrate that it works with some output that you can print and turn in. You can use the CorrectnessTestChecks code to construct a sample hierarchy.