Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  * Copyright (C) 2007 The Guava Authors
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the License for the specific language governing permissions and
 * limitations under the License.
This class provides default values for all Java types, as defined by the JLS.

Ben Yu
public final class Defaults {
  private Defaults() {}
  private static final Map<Class<?>, ObjectDEFAULTS;
  static {
    Map<Class<?>, Objectmap = new HashMap<Class<?>, Object>();
    put(mapbyte.class, (byte) 0);
    put(mapshort.class, (short) 0);
    put(mapint.class, 0);
    put(maplong.class, 0L);
    put(mapfloat.class, 0f);
    put(mapdouble.class, 0d);
     = Collections.unmodifiableMap(map);
  private static <T> void put(Map<Class<?>, ObjectmapClass<T> type, T value) {

Returns the default value of type as defined by JLS --- 0 for numbers, false for boolean and '\0' for char. For non-primitive types and void, null is returned.
  public static <T> T defaultValue(Class<T> type) {
    return (T) .get(type);
New to GrepCode? Check out our FAQ X