java 静态内部类

简介

静态内部类,就是内部类不需要this,也就是说内部类不需要引用外部类的时候使用。

code

package cn;

public class StaticInnerClassTest {
	public static void main(String[] args){
		double[]d = new double[20];
		for (int i=0; i<d.length; i++){
			d[i] = 100 * Math.random();
		}
		ArrayAlg.Pair p = ArrayAlg.minmax(d); // 调用静态内部类对象和静态内部类方法
		System.out.println("min=" + p.getFirst());
		System.out.println("max=" + p.getSecond());
	}
}

class ArrayAlg{
	public static class Pair{
		private double first;
		private double second;
		public Pair(double f, double s){
			first = f;
			second = s;
		}
		public double getFirst(){
			return first;
		}
		public double getSecond(){
			return second;
		}
	}
	public static Pair minmax(double[] values){
		double min = Double.POSITIVE_INFINITY;
		double max = Double.NEGATIVE_INFINITY;
		for(double v: values){
			if(min > v) min = v;
			if(max < v) max = v;
		}
		return new Pair(min, max);
	}
	
}

Hope is a good thing,maybe the best of things,and no good thing ever dies.----------- Andy Dufresne
原文地址:https://www.cnblogs.com/eat-too-much/p/13516890.html