Java Language Specification SE 21, §8.9 Enum Classes, defines an enum declaration as a restricted class that defines a small set of named class instances; Oracle Java SE 21 API, java.lang.Enum, documents it as the common base class for Java enumeration classes. ↩︎
Joshua Bloch, Effective Java, 3rd Edition, Item 34, frames the recommendation to use enums instead of int constants. ↩︎
Effective Java Item 34 identifies the int enum pattern and explains why it lacks the type-safety and expressiveness supplied by Java enum types. ↩︎
The apple/orange example follows Effective Java Item 34: because both constants are merely int values, the Java type system cannot distinguish the two domains at compile time. ↩︎
# URL ## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/' url:http://yoursite.com root:/ permalink::title/# :year/:month/:day/:title/ permalink_defaults: pretty_urls: trailing_index:true# Set to false to remove trailing 'index.html' from permalinks trailing_html:true# Set to false to remove trailing '.html' from permalinks
在 fake null object 中存储信息,Unity 能够在检视窗口 (Inspector) 中高亮该 GameObject,并给出更多指引。如:“looks like you are accessing a non initialized field in this MonoBehaviour over here, use the inspector to make the field point to something” (看来您试图访问此 MonoBehaviour 的未实例化字段,请在检视窗口使其指向实例)。
privatestaticboolIsNativeObjectAlive(Object o) { if (o.GetCachedPtr() != IntPtr.Zero) returntrue; return !(o is MonoBehaviour) && !(o is ScriptableObject) && Object.DoesObjectWithInstanceIDExist(o.GetInstanceID()); }
///<summary> ///<para>Returns the instance id of the object.</para> ///</summary> [SecuritySafeCritical] publicintGetInstanceID() { this.EnsureRunningOnMainThread(); returnthis.m_InstanceID; }
privatevoidEnsureRunningOnMainThread() { if (!Object.CurrentThreadIsMainThread()) thrownew InvalidOperationException("EnsureRunningOnMainThread can only be called from the main thread"); }
在 fake null object 中存储信息,Unity 能够在检视窗口 (Inspector) 中高亮该 GameObject,并给出更多指引:“looks like you are accessing a non initialized field in this MonoBehaviour over here, use the inspector to make the field point to something” (看来你在 MonoBehaviour 中试图访问未实例化字段,请在检视窗口使其指向实例)。
// Find the first employees: var earlyFolks = from e in allEmployees where e.Classification == EmployeeType.Salary where e.YearsOfService > 20 where e.MonthlySalary < 4000 select e;
// Find the newest people: var newest = from e in allEmployees where e.Classification == EmployeeType.Salary where e.YearsOfService < 20 where e.MonthlySalary < 4000 select e;
你可以将这些 where 合并为一条子句,然而这并不会带来太大区别。查询操作之间本就可以拼接 (见31条),而简单的 where 谓词还会有可能内联 (inline),因此,这两种写法在性能上是一样的。[2]
// else where var allEmployees = FindAllEmployees();
var earlyFolks = from e in allEmployees whereLowPaidSalaried(e) && e.YearsOfService > 20 select e; // Find the newest people: var newest = from e in allEmployees where e.Classification == EmployeeType.Salary where e.YearsOfService < 20 where e.MonthlySalary < 4000 select e;
privatestatic IQueryable<Employee> LowPaidSalariedFilter(this IQueryable<Employee> sequence) => from s in sequence where s.Classification == EmployeeType.Salary && s.MonthlySalary < 4000 select s;
// else where var allEmployees = FindAllEmployees();
// Find the first employees: var salaried = allEmployees.LowPaidSalariedFilter();
var earlyFolks = salaried.Where(e => e.YearsOfService > 20);
// Find the newest people: var newest = salaried.Where(e => e.YearsOfService < 2);