Skip to content

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

@sunriseLe

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;
    }

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