Skip to content

Why the size of OptoinalXxx.emty() is zero? #174

Description

@sunriseLe
  • In class SizeOf, I found the size of OptoinalXxx.emty() is zero. In my opinion, the size of empty instance should be OPTIONAL_INSTANCE_SIZE or OPTIONAL_INT_INSTANCE_SIZE.
  • Because it's an instance and will use basic memory for class layout
    public static <T> long sizeOf(Optional<T> optional, ToLongFunction<T> valueSize)
    {
        return optional != null && optional.isPresent() ? OPTIONAL_INSTANCE_SIZE + valueSize.applyAsLong(optional.get()) : 0;
    }
    
    
    public static long sizeOf(OptionalInt optional)
    {
        return optional != null && optional.isPresent() ? OPTIONAL_INT_INSTANCE_SIZE : 0;
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions