Telegram Group & Telegram Channel
➡️ Обработка CloneNotSupportedException и возврат экземпляра подкласса

Несмотря на критику функции клонирования объектов в Java, если вам нужно реализовать метод clone(), вот несколько лучших практик для упрощения задачи:

public Course clone() {
Course c = null;
try {
c = (Course)super.clone();
} catch (CloneNotSupportedException e) {} // Не произойдет

return c;
}


🗣️ Этот код использует тот факт, что метод clone() не вызовет CloneNotSupportedException, если класс реализует интерфейс Cloneable. Возврат подкласса называется ковариантным переопределением методов и доступен с Java 5, что позволяет избежать приведения типа на стороне клиента:

Course javaBeginners = new Course("Java", 100, 10);
Course clone = javaBeginners.clone();


Ранее, например, с классом Date, нужно было явно приводить результат метода clone():

Date d = new Date();
Date clone = (Date) d.clone();


Java Learning 👩‍💻
Please open Telegram to view this post
VIEW IN TELEGRAM
👍8



tg-me.com/Java_per_month/2725
Create:
Last Update:

➡️ Обработка CloneNotSupportedException и возврат экземпляра подкласса

Несмотря на критику функции клонирования объектов в Java, если вам нужно реализовать метод clone(), вот несколько лучших практик для упрощения задачи:

public Course clone() {
Course c = null;
try {
c = (Course)super.clone();
} catch (CloneNotSupportedException e) {} // Не произойдет

return c;
}


🗣️ Этот код использует тот факт, что метод clone() не вызовет CloneNotSupportedException, если класс реализует интерфейс Cloneable. Возврат подкласса называется ковариантным переопределением методов и доступен с Java 5, что позволяет избежать приведения типа на стороне клиента:

Course javaBeginners = new Course("Java", 100, 10);
Course clone = javaBeginners.clone();


Ранее, например, с классом Date, нужно было явно приводить результат метода clone():

Date d = new Date();
Date clone = (Date) d.clone();


Java Learning 👩‍💻

BY Java Learning




Share with your friend now:
tg-me.com/Java_per_month/2725

View MORE
Open in Telegram


Java Learning Telegram | DID YOU KNOW?

Date: |

How To Find Channels On Telegram?

There are multiple ways you can search for Telegram channels. One of the methods is really logical and you should all know it by now. We’re talking about using Telegram’s native search option. Make sure to download Telegram from the official website or update it to the latest version, using this link. Once you’ve installed Telegram, you can simply open the app and use the search bar. Tap on the magnifier icon and search for a channel that might interest you (e.g. Marvel comics). Even though this is the easiest method for searching Telegram channels, it isn’t the best one. This method is limited because it shows you only a couple of results per search.

Telegram hopes to raise $1bn with a convertible bond private placement

The super secure UAE-based Telegram messenger service, developed by Russian-born software icon Pavel Durov, is looking to raise $1bn through a bond placement to a limited number of investors from Russia, Europe, Asia and the Middle East, the Kommersant daily reported citing unnamed sources on February 18, 2021.The issue reportedly comprises exchange bonds that could be converted into equity in the messaging service that is currently 100% owned by Durov and his brother Nikolai.Kommersant reports that the price of the conversion would be at a 10% discount to a potential IPO should it happen within five years.The minimum bond placement is said to be set at $50mn, but could be lowered to $10mn. Five-year bonds could carry an annual coupon of 7-8%.

Java Learning from us


Telegram Java Learning
FROM USA