KivaKit Trecho #10

Jan 04 2023
Mais sobre o KivaKit https://state-of-the-art.org/https://www.
Código

package com.telenav.kivakit.snippets;

import com.telenav.kivakit.core.string.FormatProperty;
import com.telenav.kivakit.core.string.ObjectFormatter;

public class Snippet10 extends BaseSnippet
{
    public static void main(String[] args)
    {
        new Snippet10().run();
    }

    public class Alien
    {
        @FormatProperty
        private final String name;

        @FormatProperty
        private final Galaxy galaxy;

        public Alien(String name, Galaxy galaxy)
        {
            this.name = name;
            this.galaxy = galaxy;
        }

        @Override
        public String toString()
        {
            return new ObjectFormatter(this).toString();
        }
    }

    public class Galaxy
    {
        @FormatProperty
        private final String name;

        public Galaxy(String name)
        {
            this.name = name;
        }
    }

    @Override
    protected Object onSnippet()
    {
        return new Alien("Fred", new Galaxy("Andromeda")).toString();
    }
}

      
                
Output
[Snippet10.Alien galaxy = [Snippet10.Galaxy name = Andromeda], name = Fred]

Mais sobre o KivaKit

https://state-of-the-art.org/
https://www.kivakit.org/

Artigos relacionados

KivaKit Fragmento #1
KivaKit Fragmento #2
KivaKit Fragmento #3

Seis razões pelas quais a maior parte do Java que você viu não é real Java
Por que um host não é uma string e uma porta não é um inteiro
Um inteiro não é uma contagem
Tudo é dividir e conquistar