當前位置: 首頁>>代碼示例>>Java>>正文


Java Immutable類代碼示例

本文整理匯總了Java中javax.annotation.concurrent.Immutable的典型用法代碼示例。如果您正苦於以下問題:Java Immutable類的具體用法?Java Immutable怎麽用?Java Immutable使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Immutable類屬於javax.annotation.concurrent包,在下文中一共展示了Immutable類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: appendClassAnnotations

import javax.annotation.concurrent.Immutable; //導入依賴的package包/類
@Override
public void appendClassAnnotations(JMessage<?> message) throws GeneratorException {
    if (JAnnotation.isDeprecated((CAnnotatedDescriptor) message.descriptor())) {
        writer.appendln(JAnnotation.DEPRECATED);
    }
    writer.appendln("@SuppressWarnings(\"unused\")");
    if (javaOptions.generated_annotation_version) {
        writer.formatln("@%s(\"%s %s\")",
                        Generated.class.getName(),
                        generatorOptions.generator_program_name,
                        generatorOptions.program_version);
    } else {
        writer.formatln("@%s(\"%s\")",
                        Generated.class.getName(),
                        generatorOptions.generator_program_name);
    }
    writer.formatln("@%s", Immutable.class.getName());
}
 
開發者ID:morimekta,項目名稱:providence,代碼行數:19,代碼來源:CommonMemberFormatter.java

示例2: getClonedValue

import javax.annotation.concurrent.Immutable; //導入依賴的package包/類
/**
 * Get a clone (= deep copy) of the passed value. The following things are
 * tried for cloning:
 * <ol>
 * <li>If the object is immutable, it is returned as is (if it is a primitive
 * type or marked with the {@link Immutable} annotation.</li>
 * <li>If the object implements {@link ICloneable} it is invoked.</li>
 * <li>If the object implements {@link Cloneable} it is invoked.</li>
 * <li>If a copy constructor (a constructor taking one argument of the same
 * class as it declares)</li>
 * </ol>
 * If all tries fail, <code>null</code> is returned.
 *
 * @param <DATATYPE>
 *        The source and return type
 * @param aObject
 *        The object to be copied.
 * @return <code>null</code> if the passed value is <code>null</code> or if no
 *         cloning could be performed.
 */
@Nullable
public static <DATATYPE> DATATYPE getClonedValue (@Nullable final DATATYPE aObject)
{
  // null -> null
  if (aObject == null)
    return null;

  final Class <?> aClass = aObject.getClass ();

  // special handling for immutable objects without equals or clone
  if (ClassHelper.isPrimitiveWrapperType (aClass) ||
      aObject instanceof String ||
      aClass.getAnnotation (Immutable.class) != null)
    return aObject;

  // generic clone
  return _getGenericClone (aObject);
}
 
開發者ID:phax,項目名稱:ph-commons,代碼行數:39,代碼來源:CloneHelper.java


注:本文中的javax.annotation.concurrent.Immutable類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。