当前位置: 首页>>代码示例>>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;未经允许,请勿转载。