Используя this(args)
. Предпочтительный шаблон должен работать от самого маленького конструктора к самому большому.
public class Cons {
public Cons() {
// A no arguments constructor that sends default values to the largest
this(madeUpArg1Value,madeUpArg2Value,madeUpArg3Value);
}
public Cons(int arg1, int arg2) {
// An example of a partial constructor that uses the passed in arguments
// and sends a hidden default value to the largest
this(arg1,arg2, madeUpArg3Value);
}
// Largest constructor that does the work
public Cons(int arg1, int arg2, int arg3) {
this.arg1 = arg1;
this.arg2 = arg2;
this.arg3 = arg3;
}
}
можно также использовать позже защищенный подход valueOf или только:
public class Cons {
public static Cons newCons(int arg1,...) {
// This function is commonly called valueOf, like Integer.valueOf(..)
// More recently called "of", like EnumSet.of(..)
Cons c = new Cons(...);
c.setArg1(....);
return c;
}
}
Для вызова суперкласса используйте super(someValue)
. Вызов к супер должен быть первым вызовом в конструкторе, или Вы получите ошибку компилятора.
Когда я искал, как это сделать, я нашел этот пост бесценным: http://blogs.msdn.com/jmanning/articles/535573.aspx
Длинная процедура представлена в записи блога Рори Примроуза
Краткий ответ - список аргументов для сравнения:
/x /e /ub /wl /dl %6 /dr %7 %1 %2
, а список аргументов для слияния:
/x /e /ub /wl /dl %6 /dr %7 %1 %2 %4
Иногда Winmerge не возвращает 0, и TFS думает, что слияние было отменено. Вам необходимо использовать следующий командный файл оболочки для слияния:
@rem winmergeFromTFS.bat
@rem 2007-08-01
@rem File created by Paul Oliver to get Winmerge to play nicely with TFS
@rem
@rem To use, tell TFS to use this command as the merge command
@rem And then set this as your arguments:
@rem %6 %7 %1 %2 %4
"C:\Program Files\WinMerge\WinMerge.exe" /x /e /ub /wl /dl %1 /dr %2 %3 %4 %5
exit 0
Затем вы устанавливаете список аргументов:
%6 %7 %1 %2 %
exit 0