`

JAVA Geneic Programming

    博客分类:
  • JAVA
阅读更多
public class Generic<T> {
	
	public Generic() {
		head = null;
		tail = null;
	}
	public Generic(T head, T tail) {
		this.head = head;
		this.tail = tail;
	}

	public T getHead() {
		return head;
	}
	public void setHead(T head) {
		this.head = head;
	}
	public T getTail() {
		return tail;
	}
	public void setTail(T tail) {
		this.tail = tail;
	}
	
	private T head;
	private T tail;
}



public class GenericTest {

	public static <T extends Comparable> Generic<T> minmax(T[] a) {
		if (a == null || a.length == 0) {
			return null;
		}
		T max = a[0];
		T min = a[0];

		for (int i = 1; i < a.length; i++) {
			if (min.compareTo(a[i]) > 0) {
				min = a[i];
			}

			if (max.compareTo(a[i]) < 0) {
				max = a[i];
			}
		}
		return new Generic<T>(min, max);
	}

	public static void main(String[] args) {
		
		GregorianCalendar[] date = {
				new GregorianCalendar(1903,Calendar.FEBRUARY,9),
				new GregorianCalendar(1815,Calendar.JUNE,18),
				new GregorianCalendar(1910,Calendar.JULY,9),
		};
		
		Generic<GregorianCalendar> gg = minmax(date);
		System.out.println(gg.getHead().getTime()+"\n"+gg.getTail().getTime());
		
		/*String[] words = { "Marry", "Jim", "Xie", "littlep" };
		Generic<String> mm = minmax(words);
		System.out.println("min = " + mm.getHead() + "\n" + "max = "
				+ mm.getTail());*/
	}
}


分享到:
评论

相关推荐

    Java Servlet Programming 2nd Edition

    Java Servlet Programming 2nd Edition

    Java Thread Programming

    本资料“Java Thread Programming”由Paul Hyde提供,包含了关于Java线程编程的理论知识和实践代码,旨在帮助开发者深入理解和熟练掌握Java线程。 首先,我们来了解一下Java中线程的基本概念。在Java中,可以通过两...

    Java Database Programming Bible

    《Java Database Programming Bible》是Java数据库编程领域的一本权威指南,深入浅出地讲解了如何在Java应用程序中与各种数据库进行交互。这本书涵盖了从基础到高级的Java数据库编程技术,旨在帮助开发者熟练掌握...

    java network programming by Elliotte Rusty Harold

    《Java网络编程》是Elliotte Rusty Harold撰写的一本经典书籍,主要涵盖了Java平台上的网络应用程序开发。这本书深入浅出地介绍了如何使用Java进行网络通信,包括套接字编程、HTTP协议、DNS解析以及多线程等核心概念...

    Learn Java 17 Programming 2nd Edition

    ### Java 17 Programming Key Concepts and Features The title "Learn Java 17 Programming 2nd Edition" indicates that this book is an updated guide designed to teach the basics of Java programming, ...

    Programming Finite Elements in Java

    Programming Finite Elements in Java™ teaches the reader FEM algorithms and their programming in Java™ through a single finite element Java™ program. The compact, simple code makes it straight...

    Java 9 Programming Blueprints epub

    Java 9 Programming Blueprints 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除

    Introduction to Java programming 8th

    become proficient Java programmers A brief version Introduction to Java Programming Brief Version Eighth Edition is available for a first course on programming commonly known as CS1 The brief version ...

    Java 9 Programming Blueprints .pdf

    根据提供的文件信息,以下是从标题、描述、标签以及部分内容中生成的Java 9编程相关知识点: 1. Java 9新特性:文件中提到的Java 9的几个关键新特性包括模块化、进程处理API、REPL(Read-Eval-Print Loop,即交互式...

    Java Extreme Programming Cookbook epub

    Java Extreme Programming Cookbook 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除

    Java Servlet Programming9

    在"Java Servlet Programming9"这个主题中,我们可以深入探讨以下几个核心知识点: 1. **Servlet基础**:Servlet是Java平台上的一个标准API,定义了服务器端组件与HTTP协议交互的接口。`javax.servlet`和`javax....

    Java 9 Programming By Example

    《Java 9编程实战》是一本深入探讨Java 9新特性和编程实践的书籍,旨在帮助开发者更好地理解和应用这一版本的Java。Java 9作为Java平台的重要更新,引入了许多改进和创新,使得开发者能更高效地编写代码和管理模块。...

    Java Extreme Programming Cookbook(英文版).chm

    Java Extreme Programming Cookbook,Java极限编程,

    Java Network Programming and Distributed Computing

    ### Java网络编程与分布式计算关键知识点 #### 一、Java网络编程基础 ##### 1. 网络架构与TCP/IP协议 - **互联网架构**:本书首先介绍了互联网的基本架构,包括不同层次的功能划分以及各层之间的交互方式。这对于...

Global site tag (gtag.js) - Google Analytics