Сообщения за Январь, 2017

OOP Java

static and super keyword
          super.static can't because:

          Overriding depends on having an instance of a class. The point of polymorphism is that you can subclass a class and the objects implementing those subclasses will have different behaviors for the same methods defined in the superclass (and overridden in the subclasses). A static method is not associated with any instance of a class so the concept is not applicable.

There were two considerations driving Java's design that impacted this. One was a concern with performance: there had been a lot of criticism of Smalltalk about it being too slow (garbage collection and polymorphic calls being part of that) and Java's creators were determined to avoid that. Another was the decision that the target audience for Java was C++ developers. Making static methods work the way they do had the benefit of familiarity for C++ programmers and was also very fast, because there's no need to wait until runtime to fig…

java singleton implementations


для объектным ссылок volatile можно не писать. я прав?
Например, когда мы в многопоточном приложении используем паттерн Синглтон в котором применяем синхронизацию и хотим чтобы синхронизация осуществлялась только один раз при инициализации объекта, а не каждый раз, когда мы вызываем getInstance(), тогда модификатора volatile используем для объектной ссылки:
public class Singleton {
    private static volatile Singleton instance;
    private Singleton(){
    public static Singleton getInstance() {
        if (instance == null) {
            synchronized(Singleton.class) {
                if (instance == null)
                    instance = new Singleton();
        return instance;

volatile это сурово

DCL https://web.archive.org/web/20121108114236/http://habrahabr.ru/post/143390/