“control” is defined as an accessor in class 'ParentClass, but is overridden here in 'ChildClass" as an instance property - migration

export class ChildClass extends ParentClass implements OnInit {
#Input () control: FormControl;
}
#Directive()
export abstract class ParentClass implements OnInit, OnDestroy {
get control(): AbstractControl {
return this.page && this.page. getControl(this.content.id);
}
But while doing npm start getting below error.
“control” is defined as an accessor in class 'ParentClass, but is overridden here in 'ChildClass" as an instance property.
Getting this error while migrating existing angular 10 application into angular 11.

Related

Sap Spartacus 4.3 extend ProductListComponent

I have this constructor in my class.
export class CustomProductListComponent extends ProductListComponent implements OnInit, OnDestroy {
constructor(
protected pageLayoutService: PageLayoutService,
protected productListComponentService: ProductListComponentService,
protected scrollConfig: ViewConfig,
) {
super(pageLayoutService, productListComponentService, scrollConfig);
}
}
However, it gives me an error of
"Class 'CustomProductListComponent' incorrectly extends base class 'ProductListComponent'.
Property 'pageLayoutService' is private in type 'ProductListComponent' but not in type 'CustomProductListComponent'.ts(2415)
"
Do you know to solve the pageLayoutService since its private in base class?

How to provide the base class in Koin?

For example I the following classes:
abstract class BaseClass()
class SpecificClass : BaseClass()
Now, I want to provide SpecificClass through koin dependency inject but I also want to provide the base class BaseClass in the same graph.
To be clear I want to do something like:
class Someclass {
...
private specificClass: SpecificClass by inject()
...
}
class Someclass {
...
private baseClass: BaseClass by inject()
// where this BaseClass is just the the same instace of the SpecificClass in the dependency graph
...
}
How do I do my module to do this? How can I inject the implementation instance to the baseClass reference?
You can do it using Koin in 2 ways
Methodn 1
You can create dependencies for both of them like this
single {
SpecificClass()
}
single<BaseClass> {
get<SpecificClass>()
}
In this way, whenever you inject an instance, it will get injected accordingly
Method 2
You can make use of named dependencies like this
single("BaseClassImpl") {
SpecificClass()
}
And when you want to inject it, provide key for that dependency like this:
class Someclass {
...
private specificClass: SpecificClass by inject("BaseClassImpl")
...
}
class Someclass {
...
private baseClass: BaseClass by inject("BaseClassImpl")
// where this BaseClass is just the the same instace of the SpecificClass in the dependency graph
...
}
You can't inject abstract classes.
In order to inject a class, it must be instantiable and abstract classes are not.
To inject SpecificClass with Koin you need to create a module:
val appModule = module {
single {
SpecificClass()
}
}
Initialize it in your application class:
class MyApplication : Application() {
override fun onCreate(){
super.onCreate()
// start Koin!
startKoin {
// declare used Android context
androidContext(this#MyApplication)
// declare modules
modules(appModule)
}
}
}
And use the inject delegation in your activity/fragment
class MyActivity() : AppCompatActivity() {
val specificClass : SpecificClass by inject()
}

Deadbolt 2.5.0, unable to instantiate custom SubjectPresentHandler extending AbstractDeadboltHandler

I am using deadbolt 2.5.0 and I have created custom SubjectPresentHandler as below:
public class SubjectPresentHandler extends AbstractDeadboltHandler
{
public SubjectPresentHandler(ExecutionContextProvider ecProvider) {
super(ecProvider);
}
// other required methods
}
And, I also have :
#Singleton
public class CustomDeadboltHandlerCache implements HandlerCache
{
private final DeadboltHandler defaultHandler = new SubjectPresentHandler();
// other required code
}
Now the problem that I am facing here is I cannot instantiate SubjectPresentHandler using its default contructor. I get an error as: "The constructor SubjectPresentHandler is undefined". Now when I add default constructor in SubjectPresentHandler as below:
public SubjectPresentHandler() {
super();
}
I get an error as:
The constructor AbstractDeadboltHandler is undefined. If I try removing the paramaterized constructor in SubjectPresentHandler then I get error message as
"Implicit super constructor AbstractDeadboltHandler() is undefined for default constructor. Must define an explicit constructor".
I am not sure how can I resolve this, thus seeking solution regarding this issue.
The constructor of SubjectPresentHandler takes an ExecutionContextProvider as a parameter. The easiest way to do this is to inject one and have the creation of the handler done via Guice.
The ExecutionContextProvider is provided by DeadboltModule - you can see this here.
#Singleton
public class SubjectPresentHandler extends AbstractDeadboltHandler
{
#Inject
public SubjectPresentHandler(ExecutionContextProvider ecProvider) {
super(ecProvider);
}
// other required methods
}
You can also inject the handler into the handler cache:
#Singleton
public class CustomDeadboltHandlerCache implements HandlerCache
{
private final DeadboltHandler defaultHandler;
#Inject
public CustomDeadboltHandlerCache(final DeadboltHandler defaultHandler) {
this.defaultHandler = defaultHandler;
}
// other required code
}
If you have multiple handlers, take a look at the documentation for how to handle this.

Kotlin: Visibility of static nested Java class declared inside a non-visible class

Using java my static-nested java class is visible, but using Kotlin it is not. See my example below. Is there a good reason it is not allowed, or is it a bug? And are there any workarounds so that I can extend NestedStaticClass from Kotlin?
I have a package-private java class containing the static-nested class
package javapackage;
class HiddenClass {
public static class NestedStaticClass {}
}
HiddenClass is extended by a public class.
package javapackage;
public class VisibleClass extends HiddenClass{}
From my java class extending VisibleClass, I can see NestedStaticClass (It compiles)
package otherpackage;
import javapackage.VisibleClass;
public class JavaClass extends VisibleClass {
public static class C4 extends NestedStaticClass {}
public JavaClass() {
new NestedStaticClass();
}
}
But from Kotlin this does not work. I get the compile error: "Unresolved reference NestedStaticClass"
package otherpackage
import javapackage.VisibleClass
class KotlinClass() : VisibleClass() {
class C1() : NestedStaticClass()
init {
val v = NestedStaticClass()
}
}

Guice's AOP extension not working on super type

I have a following hierarchical structure:
public class ItemImpl extends RepositoryBase<ItemImpl> {
#Inject
ItemImpl( dependency ) {
super( dependency )
}
}
public class RepositoryBase<T> extends Base<T> {
public RepositoryBase( dependency ) { //Constructor without #Inject
super( dependency )
}
#Intercept <--- Works
public someMethod( ) {}
}
public class Base<T> {
public Base( dependency ){ } //Constructor without #Inject
#Intercept <--- Does not work ***
public someMethod( ) {}
}
As you can see above, Interception does not work at the level 3 of the hierarchy. According to Guice's AOP limitation, instance have to be created using Guice and child ItemImpl has constructor with #Inject so I guessed parents of this child should work.
Why doesn't interception at level 3 work and why does the interception at level 2 work? Both of the parents does not have constructor with #Inject?
Cglib creates a dynamic sub class that overrides an intercepted method where Guice applies its magic in this overriden method. This can only be done for the "top" method but not for "grand parent" methods. Therefore, only the method in RepositoryBase is intercepted while the method defined in Base is hidden from Guice.
Note that it is technically possible to create byte code that calls a grand parent method. Cglib does however not offer such capabilities.