Recursion hell
This commit is contained in:
Binary file not shown.
14
Semester 3/Assignments/lab6_generics_CalebFontenot/pom.xml
Normal file
14
Semester 3/Assignments/lab6_generics_CalebFontenot/pom.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>edu.slcc.asdv.caleb</groupId>
|
||||
<artifactId>lab6_generics_CalebFontenot</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<exec.mainClass>edu.slcc.asdv.caleb.lab6_generics_calebfontenot.Lab6_generics_CalebFontenot</exec.mainClass>
|
||||
</properties>
|
||||
</project>
|
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
*/
|
||||
|
||||
package edu.slcc.asdv.caleb.lab6_generics_calebfontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class Lab6_generics_CalebFontenot {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello World!");
|
||||
}
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package edu.slcc.asdv.caleb.lab6_generics_calebfontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class Max {
|
||||
|
||||
public static Comparable max(Comparable o1, Comparable o2)
|
||||
{
|
||||
if (o1.compareTo(o2) > 0) {
|
||||
return o1;
|
||||
} else {
|
||||
return o2;
|
||||
}
|
||||
}
|
||||
public static <E extends Comparable<E>> E maxSafe(E e1, E e2) {
|
||||
if(e1.compareTo(e2) > 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("abc", "ABC"));
|
||||
System.out.println();
|
||||
//System.out.println(maxSafe(1, "two"));
|
||||
System.out.println("This line compiles but crashes the program " + max(1, "two"));
|
||||
} catch (ClassCastException e) {
|
||||
System.err.println("RAW TYPES ARE UNSAFE " + e.getMessage()) ;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user