2014-04-15 55 views
0

我只是在看的Integer類的源代碼,我在這些線路傳來:Java的Integer類[使用Eclipse查看源代碼]

public static final int MAX_VALUE = Integer.MAX_VALUE; 
public static final int MIN_VALUE = Integer.MIN_VALUE; 

這是唯一的地方MAX_VALUE或MIN_VALUE是在Integer類中聲明,所以它似乎值分配給自己...

但是,當我嘗試打印的價值觀,我得到:

2147483647 -> 0x7fffffff 
-2147483648 -> 0x80000000 

所以還是產生正確的VALU e,但它分配在哪裏?我使用Eclipse的

我不能在網上找到代碼中的最新的Java(8),所以我只會粘貼相關代碼在這裏:

package java.lang; 

import sun.misc.VM; 

public final class Integer 
    extends Number 
    implements Comparable<Integer> 
{ 
    public static final int MIN_VALUE = Integer.MIN_VALUE; 
    public static final int MAX_VALUE = Integer.MAX_VALUE; 
    ... 
} 

解決此之後,似乎日食修改某些jar文件的源代碼。最佳觀看方式

+0

這不是我所看到的。我在安裝Java 8時下載了源代碼,並在編輯器(而不是Eclipse)中查看它。更新:我在Eclipse中也沒有看到它。 – ajb

+0

Eclipse可能無法訪問實際的源,因此試圖從其他信息「重建」源?這也許可以解釋爲什麼您發佈的「相關代碼」代碼段中沒有任何評論。 – ajb

+0

也許,但我現在要使用文本編輯器來看看實際的源代碼。我會發布我發現的 – smac89

回答

2

您確定您正在尋找合適的源代碼,而不僅僅是IDE中的編譯類。我有以下幾點:

/** 
* A constant holding the minimum value an {@code int} can 
* have, -2<sup>31</sup>. 
*/ 
public static final int MIN_VALUE = 0x80000000; 

/** 
* A constant holding the maximum value an {@code int} can 
* have, 2<sup>31</sup>-1. 
*/ 
public static final int MAX_VALUE = 0x7fffffff; 

grep的代碼一致: http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/lang/Integer.java

+0

的答案,我同意。我看着我的jdk1.7.0_25/src.zip,並看到與monkjack相同的東西。 – Nayuki

+1

感謝你發佈這個,我的方式是關閉我的答案= P – DerStrom8

+0

我提到我使用的是java 8,所以jre8和jdk1.8.0。您正在使用的是jdk1.7.40 – smac89