lazy-initialization

Lazy instantiation in Objective-C/ iPhone development

时光毁灭记忆、已成空白 提交于 2019-11-27 11:41:50
Quick question... Well I understand that all properties start out as nil in Objective-C and that sending a message to nil does nothing, therefore you must initialize using [[Class alloc] init]; before sending a message to a newly created property. However, what about if I'm not sending messages to this property or if I set the property using self.property = something? Do I need to alloc init in these cases as well? Also, do UI properties start out as nil as well, such as a UILabel property that you drag out from your storyboard? Do these need alloc init? Thanks to all who answer Jason C.

Does .net core dependency injection support Lazy<T>

南楼画角 提交于 2019-11-27 05:51:29
问题 I am trying to use the generic Lazy class to instantiate a costly class with .net core dependency injection extension. I have registered the IRepo type, but I'm not sure what the registration of the Lazy class would look like or if it is even supported. As a workaround I have used this method http://mark-dot-net.blogspot.com/2009/08/lazy-loading-of-dependencies-in-unity.html config: public void ConfigureService(IServiceCollection services) { services.AddTransient<IRepo, Repo>(); //register

Lazy field initialization with lambdas

筅森魡賤 提交于 2019-11-27 03:33:41
I would like to implement lazy field initialization (or deferred initialization) without an if statement and taking advantage of lambdas. So, I would like to have the same behavior of the following Foo property but without the if : class A<T>{ private T fooField; public T getFoo(){ if( fooField == null ) fooField = expensiveInit(); return fooField; } } Ignore the fact that this solution is not guaranteeing safe use for: 1) multi-threading; 2) null as a valid value of T . So, to express the intention that the initialization of the fooField is deferred until its first use I would like to declare

Thread safe lazy construction of a singleton in C++

﹥>﹥吖頭↗ 提交于 2019-11-27 02:52:58
Is there a way to implement a singleton object in C++ that is: Lazily constructed in a thread safe manner (two threads might simultaneously be the first user of the singleton - it should still only be constructed once). Doesn't rely on static variables being constructed beforehand (so the singleton object is itself safe to use during the construction of static variables). (I don't know my C++ well enough, but is it the case that integral and constant static variables are initialized before any code is executed (ie, even before static constructors are executed - their values may already be

Kotlin lazy properties and values reset: a resettable lazy delegate

坚强是说给别人听的谎言 提交于 2019-11-27 01:52:16
问题 So I use kotlin for android, and when inflating views, I tend to do the following: private val recyclerView by lazy { find<RecyclerView>(R.id.recyclerView) } This method will work. However, there is a case in which it will bug the app. If this is a fragment, and the fragment goes to the backstack, onCreateView will be called again, and the view hierarchy of the fragment will recreated. Which means, the lazy initiated recyclerView will point out to an old view no longer existent. A solution is

Using JPA entities in JSF. Which is the best strategy to prevent LazyInitializationException?

点点圈 提交于 2019-11-27 01:46:30
Would like to hear experts on best practice of editing JPA entities from JSF UI. So, a couple of words about the problem. Imagine I have the persisted object MyEntity and I fetch it for editing. In DAO layer I use return em.find(MyEntity.class, id); Which returns MyEntity instance with proxies on "parent" entities - imagine one of them is MyParent . MyParent is fetched as the proxy greeting to @Access(AccessType.PROPERTY) : @Entity public class MyParent { @Id @Access(AccessType.PROPERTY) private Long id; //... } and MyEntity has the reference to it: @ManyToOne(fetch = FetchType.LAZY)

Swift lazy instantiating using self

独自空忆成欢 提交于 2019-11-26 19:06:34
I have something that really puzzles me, specifically the following code triggers a compiler error "unresolved identifier self", and I am not sure why this is happening, as lazy means that at the time the property will be used, the class is already instantiated. Am I missing something? Many thanks in advance. Here is the code class FirstClass { unowned var second: SecondClass init(second:SecondClass) { self.second = second print("First reporting for duty") } func aMethod() { print("First's method reporting for duty") } } class SecondClass { lazy var first = FirstClass(second: self) func

LazyInitializationException in selectManyCheckbox on @ManyToMany(fetch=LAZY)

戏子无情 提交于 2019-11-26 17:03:01
问题 What is the best way to handle multiple chackboxes when you nead to fill a JPA M:N relation ... for example I have an JPA entity Hardware and the entity Connectivity. Hardware has a set for connectivity : private Set<Connectivity> connectivities = new HashSet<Connectivity>(0); and has a setter and getter like this : @ManyToMany(fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.REFRESH }, mappedBy = "hwProviders") public Set<Connectivity> getConnectivities() { return this

Lazy instantiation in Objective-C/ iPhone development

不打扰是莪最后的温柔 提交于 2019-11-26 15:41:16
问题 Quick question... Well I understand that all properties start out as nil in Objective-C and that sending a message to nil does nothing, therefore you must initialize using [[Class alloc] init]; before sending a message to a newly created property. However, what about if I'm not sending messages to this property or if I set the property using self.property = something? Do I need to alloc init in these cases as well? Also, do UI properties start out as nil as well, such as a UILabel property

How to solve the LazyInitializationException when using JPA and Hibernate

烂漫一生 提交于 2019-11-26 15:07:35
I am working on a project for a customer who wants to use lazy initialization. They always get "lazy initialization exception" when mapping classes with the default lazy loading mode. @JoinTable(name = "join_profilo_funzionalita", joinColumns = {@JoinColumn(name = "profilo_id", referencedColumnName = "profilo_id")}, inverseJoinColumns = {@JoinColumn(name = "funzionalita_id", referencedColumnName = "funzionalita_id")}) //@ManyToMany(fetch=FetchType.EAGER) - no exceptions if uncommented @ManyToMany private Collection<Funzionalita> funzionalitaIdCollection; Is there a standard pattern using JPA