---
title: "程序判断java版本"
author: "zcmor"
date: "2012-07-01T11:51:44Z"
tags: ["java version", "netty"]
categories: ["编程语言"]
slug: "java"
draft: false
lastmod: "2012-07-01T11:51:44Z"
id: 1573189
url: "https://zcmor.iteye.com/blog/1573189"
---

下面是摘自netty的源码，由于判断运行的java 版本。

    private static int javaVersion0() {
        try {
            // Check if its android, if so handle it the same way as java6.
            //
            // See https://github.com/netty/netty/issues/282
            Class.forName("android.app.Application");
            return 6;
        } catch (ClassNotFoundException e) {
            //Ignore
        }

        try {
            Deflater.class.getDeclaredField("SYNC_FLUSH");
            return 7;
        } catch (Exception e) {
            // Ignore
        }

        try {
            Double.class.getDeclaredField("MIN_NORMAL");
            return 6;
        } catch (Exception e) {
            // Ignore
        }

        return 5;
    }