ASDV-Java/Semester 3/Assignments/lab6_generics_CalebFontenot/Printed HTMLs/Max.html
2023-09-22 16:25:19 -05:00

71 lines
2.5 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Max.java</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
<!--
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
.literal {color: #cc7832}
.comment {color: #808080}
.whitespace {color: #505050}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 3/Assignments/lab6_generics_CalebFontenot/src/main/java/edu/slcc/asdv/caleb/lab6_generics_calebfontenot/Max.java</td></tr></table>
<pre>
<span class="comment">/*</span>
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license</span>
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template</span>
<span class="comment"> */</span>
<span class="literal">package</span> edu.slcc.asdv.caleb.lab6_generics_calebfontenot;
<span class="comment">/**</span>
*
* @author caleb
*/
public class Max {
public static Comparable max(Comparable o1, Comparable o2)
{
if (o1.compareTo(o2) &gt; 0) {
return o1;
} else {
return o2;
}
}
public static &lt;E extends Comparable&lt;E&gt;&gt; E maxSafe(E e1, E e2) {
if(e1.compareTo(e2) &gt; 0) {
return e1;
} else {
return e2;
}
}
public static void main(String[] args)
{
System.out.println(max(1, 2));
try {
System.out.println(maxSafe(1, 2));
System.out.println(maxSafe(&quot;abc&quot;, &quot;ABC&quot;));
System.out.println();
//System.out.println(maxSafe(1, &quot;two&quot;));
GenericStack stackUnsafe = new GenericStack();
GenericStack&lt;Integer&gt; stackSafe = new GenericStack();
stackSafe.push(1); stackSafe.push(2);
System.out.println(stackSafe);
stackUnsafe.push(1); stackUnsafe.push(&quot;two&quot;);
System.out.println(&quot;This line compiles but crashes the program &quot; + max(1, &quot;two&quot;));
} catch (ClassCastException e) {
System.err.println(&quot;RAW TYPES ARE UNSAFE &quot; + e.getMessage()) ;
}
}
}
</pre></body>
</html>