KivaKit Extrait #10

Jan 04 2023
En savoir plus sur KivaKit https://state-of-the-art.org/https://www.
Code

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]

En savoir plus sur KivaKit

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

Articles Liés

Extrait KivaKit #1
Extrait KivaKit #2
Extrait KivaKit #3

Six raisons pour lesquelles la plupart des Java que vous avez vus ne sont pas du vrai Java
Pourquoi un hôte n'est pas une chaîne et un port n'est pas un entier
Un entier n'est pas un compte
Tout est diviser pour régner