-1
这是String类IBM /基于WebSphere的Java 64年8月1日如何从Java中的String类设置disableCopyInSubstring系统属性?
/**
* This is a System property to disable copying the String when offset is non-zero in {@link #substring(int)}} and {@link #substring(int, int)}}
*/
static boolean disableCopyInSubstring;
我想设置的属性,像这样的一个片段。
System.setProperty("java.lang.String.disableCopyInSubstring", "true");
但是,显然这是不设置它,因为我调试到String类和变量仍呈现false
的正确方法。
从我正在使用的String类添加更大的片段。这是IBM的Websphere Java 1.8.64。当我问我最初以为我在使用Oracle的Java。以下是该变量及以上的片段。
package java.lang;
/*
* Licensed Materials - Property of IBM,
* Copyright IBM Corp. 1998, 2016 All Rights Reserved
*/
import java.io.Serializable;
import java.util.Locale;
import java.util.Comparator;
import java.io.UnsupportedEncodingException;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import java.util.Formatter;
import java.util.StringJoiner;
import java.util.Iterator;
import java.nio.charset.Charset;
/**
* Strings are objects which represent immutable arrays of
* characters.
*
* @author OTI
* @version initial
*
* @see StringBuffer
*/
public final class String implements Serializable, Comparable<String>, CharSequence {
// DO NOT CHANGE OR MOVE THIS LINE
// IT MUST BE THE FIRST THING IN THE INITIALIZATION
private static final boolean STRING_OPT_IN_HW = StrCheckHWAvailable();
private static final long serialVersionUID = -6849794470754667710L;
/**
* CaseInsensitiveComparator compares Strings ignoring the case of the
* characters.
*/
private static final class CaseInsensitiveComparator implements Comparator<String>, Serializable {
static final long serialVersionUID = 8575799808933029326L;
/**
* Compare the two objects to determine
* the relative ordering.
*
* @param o1 an Object to compare
* @param o2 an Object to compare
* @return an int < 0 if object1 is less than object2,
* 0 if they are equal, and > 0 if object1 is greater
*
* @exception ClassCastException when objects are not the correct type
*/
public int compare(String o1, String o2) {
return o1.compareToIgnoreCase(o2);
}
};
/**
* A Comparator which compares Strings ignoring the case of the
* characters.
*/
public static final Comparator<String> CASE_INSENSITIVE_ORDER = new CaseInsensitiveComparator();
private static final char[] ascii;
private static String[] stringArray;
private static final int stringArraySize = 10;
private static class UnsafeHelpers {
public final static long valueFieldOffset = getValueFieldOffset();
static long getValueFieldOffset() {
try { return sun.misc.Unsafe.getUnsafe().objectFieldOffset(String.class.getDeclaredField("value")); }
catch (NoSuchFieldException e) { throw new RuntimeException(e); }
}
}
/**
* This is a System property to enable copy in {@link #String(String)}}
*/
static boolean enableCopy;
/**
* This is a System property to disable copying the String when offset is non-zero in {@link #substring(int)}} and {@link #substring(int, int)}}
*/
static boolean disableCopyInSubstring;
你确定这段代码来自java.lang.String吗?我无法在任何地方找到此属性.. – ggradnig
您是使用OpenJDK还是其他供应商? – talex
我在1.8.77找不到它。但是,由于您在源代码中找到了该变量,因此请在源代码中搜索它所在的位置进行更改。 –