Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

constructor overloading ambiguity resolved

public class Player
{
    private final String name;
    private final int nationalRank;
    private final int internationalRank;

    // Constructor becomes private
    private Player(final Builder builder)
    {
        name = builder.name;
        nationalRank = builder.nationalRank;
        internationalRank = builder.internationalRank;
    }

    public static Builder withName(final String name)
    {
        return new Builder(name);
    }

    // Inner builder class
    public static class Builder
    {
        private final String name;
        private int nationalRank;
        private int internationalRank;

        private Builder(final String name)
        {
            this.name = name;
        }

        public Builder withNationalRank(int rank)
        {
            nationalRank = rank;
            return this;
        }

        public Builder withInternationalRank(int rank)
        {
            internationationalRank = rank;
            return this;
        }

        public Player build()
        {
            return new Player(this);
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: LayerRenderer 
Java :: Reason: Failed to load driver class com.mysql.cj.jdbc.Driver in either of HikariConfig class loader or Thread context classloader 
Java :: java.lang.ArrayIndexOutOfBoundsException: 4 
Java :: how to use int 
Java :: Java Insert Elements 
Java :: how do I change the opacity of a JButton 
Java :: priorityQueue peek java 
Java :: Java object of the file 
Java :: java max array 
Java :: Caused by: java.lang.ClassNotFoundException: 
Java :: install java 11 
Java :: findview by id in android 
Java :: java lambda 
Java :: java while loop 
Java :: how to check if array is full java 
Java :: print a letter in java 
Java :: lombok 
Java :: springboot avoid generated security password: 
Java :: java transaction example 
Java :: Mila Kunis 
Java :: como limpar a tela do consola no java 
Sql :: mysql disable safe mode 
Sql :: postgresql remove not null constraint 
Sql :: Port 5432 is already in use Usually this means that there is already a PostgreSQL server running on your Mac. If you want to run multiple servers simultaneously, use different ports. 
Sql :: check connections to database postgres 
Sql :: oracle list columns schema 
Sql :: how to export database mysql terminal ubuntu 
Sql :: postgres remove database 
Sql :: mysql update part of string 
Sql :: mysql get last row 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =