import java.util.Arrays;

/**
 * {@link <a href=
 * "https://[Log in to view URL]"
 * target="_blank">Costructor copy</a>}
 * 
 * @author itammb ( Italia Massimiliano Buscati )
 * @version JDK 1.15
 *
 */
class Main {
	private static final class Text implements Cloneable {
		private char[] characters;

		public Text(char[] characters) {
			this.characters = characters;
		}

		public char[] getCharacters() {
			return characters;
		}

		/**
		 * @see Arrays#hashCode(char[])
		 *
		 */
		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + Arrays.hashCode(characters);
			return result;
		}

		/**
		 * @see Arrays#equals(char[], char[])
		 *
		 */
		@Override
		public boolean equals(Object obj) {
			if (this == obj) {
				return true;
			}
			if (!(obj instanceof Text)) {
				return false;
			}
			Text other = (Text) obj;
			return Arrays.equals(characters, other.characters);
		}

		/**
		 * @see String#format(String, Object...)
		 * @see Arrays#copyOf(char[], int)
		 * 
		 *      {@link Math#min(double, double)}
		 *
		 */
		@Override
		public String toString() {
			final int maxLen = 10;
			return String.format("Text [characters=%s]",
					characters != null ? Arrays.toString(Arrays.copyOf(characters, Math.min(characters.length, maxLen)))
							: null);
		}
	}

	public static void main(String args[]) throws Exception {
		// Unit test - contenuto/indirizzo di una copia tramite il costruttore del
		// oggetto

		Text text = new Text(new char[] { 'I', 'T', 'A', 'L', 'O' });
		System.out.println(text.getCharacters());

		Text textCostructorCopy = new Text(text.getCharacters());
		System.out.println(textCostructorCopy.getCharacters());

		// oggeto generato da una copia per mezzo del costruttore, modifica la variabile
		// d'istanza del
		// oggetto text ( stesso tipo )
		char[] textContent = textCostructorCopy.getCharacters();

		textContent[0] = 'B';
		textContent[1] = 'I';
		textContent[2] = 'K';
		textContent[3] = 'E';
		textContent[4] = '*';

		System.out.println(text.getCharacters());

		if (text.equals(textCostructorCopy))
			System.out.println("text (contenuto) == textCostructorCopy (contenuto)");
		else
			System.out.println("text (contenuto) != textCostructorCopy (contenuto)");

		if (text == textCostructorCopy)
			System.out.println("text (indirizzo) == textCostructorCopy (indirizzo)");
		else
			System.out.println("text (indirizzo) != textCostructorCopy (indirizzo)");

		if (text.getCharacters() == textCostructorCopy.getCharacters())
			System.out.println("text.characters (indirizzo) == textCostructorCopy.characters (indirizzo)");
		else
			System.out.println("text.characters (indirizzo) != textCostructorCopy.characters (indirizzo)");
	}
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: