If I want to override a method in a class then I press Ctrl + O short key that list all the methods that are available for overriding.
Do I have a similar short key to override Constructors?
Ctrl + O currently list only methods no information about constructors available.
Thanks!
In case there is BaseClass and the SubClass that extends the base one, there is a quick-fix to "Create constructor matching super" in IntelliJ IDEA (it's available when you "Alt+Enter" on the class SubClass extends BaseClass{}). Please also see the discussion on constructor overriding in Java: Is Constructor Overriding Possible?
Related
Is there a quick easy way to have IntelliJ identify the superclass or interface defining the method being called in a class?
For example, in the following example, the fireEvent method is being called on the implicit this but this method is not defined within this Java class being edited in IntelliJ 2018.3. Is there some way to ask IntelliJ which of the several interfaces being implemented as well as any parent in the superclass hierarchy defines this particular method?
…
private void doIt() {
…
fireEvent( event ) ;
}
What I am asking is for the opposite of this Question, Does IntelliJ have the equivalent of the Eclipse “method view”?. That Question asks “for a given class, what are its methods offered?”. I am asking “for a given method being invoked, from what inherited superclass or interface is that method defined?”.
I generally just context-click (Ctrl-click on PC, Command-click on macOS) to navigate to the source for a method. The .java file of the superclass or interface opens in the editor.
In order to avoid navigating away, you can also context-hover. Another option is showing the javadoc via context-q when the cursor is somewhere in the method name.
If I have the following class hierarchy:
abstract class Foo<out T : Bar>() {
abstract protected val thing: T
}
class Baz : Foo<BarImpl> {
override protected val thing: T = ...
}
I get a warning on Baz::thing saying:
Redundant visibility modifier
Does that mean the compiler treats it as protected without you needing to specify that, or that it has to be public?
You will receive an IDE inspection style warnings in Kotlin for things like extra semi-colons you don't need, an extra generic type parameters that can already be inferred, and more. Yours for redundant visibility modifier is along the same lines.
If you expand the inspection message you will see the full text:
This inspection reports visibility modifiers which match the default visibility of an element (public for most elements, protected for members that override a protected member).
And you can turn the inspection off within your IDE if you no longer what to see it.
A few more notes about this:
When overriding a method or member of an ancestor class you are already at the same access level as when it was declared. Saying protected is stating the obvious (to the compiler which knows it is protected).
You are allowed to restate the access modifier again if you want. And you can open it up more, by changing it to public. But you cannot restrict it further, for example going to private (because if it is private how could you override it, that idea is incompatible with override) which becomes a compiler error.
In my current project, a circuit drawing program, I'm deriving many classes from the same base class.
Public MustInherit Class clsCompo
Public Class clsRelay Inherits clsCompo
Public Class clsResistor Inherits clsCompo
Each child class has a 'getIcon' function that provides the desired image of the component. These get loaded in a listview to be used in the drawing program.
Is there an easy way to instantiated these classes to be used? Is there another way than manually instantiating each class? And then adding the image to the listview: something like:
Dim classes() As String = {"clsResistor", "clsRelay"}
Dim c(1) As Object
For Each cls As String In classes
c(1) = New cls
'add image to listview
Next
I'm using .NET 3.5
Thanks
If your classes have a parameterless constructor:
c(1) = Activator.CreateInstance(Type.GetType("MyNamespace." & cls))
Obviously, MyNamespace. should be replaced as appropriate.
You will need to use reflection and Activator.CreateInstance specifically to perform this trick. Going towards reflection path is dangerous, and usually brings more trouble than it gives benefits. In most cases there is a better way to design your application.
In your particular case, you could have a dictionary of icons, string to icon match, then just have a constructor of clsCompo specify the icon you want as a parameter. Unless you are using inheritance for something else, this should totally solve your problem, without the burden of using reflection.
If I have an interface like this:
public interface GenericDAO<T, PK>
and I want to extend that interface in IntelliJ I will use ctrl-space at this point:
public interface ApplicationDAO extends Generic
And I would expect this:
public interface ApplicationDAO extends GenericDAO<T, PK>
But instead I get
public interface ApplicationDAO extends GenericDAO
With no indication that generics are available. Is there a way to get it to do this correctly? I am new to IntelliJ so I am stil learning all it's ins and outs.
There's no way currently in IDEA to insert such invalid generics. To know that they're there, you can look at the completion list, they're depicted in the suggestion. You can also enable "Raw use of parameterized class" inspection so that each class use without generics will be highlighted yellow in the editor.
I'm currently creating a class that extends UIComponent in Flex 3, but when the flash builder try to compile show me some errors
1044: Interface method createAutomationIDPartWithRequiredProperties in namespace mx.automation:IAutomationObject not implemented by class components:ArtWorkImage
1044: Interface method get automationEnabled in namespace mx.automation:IAutomationObject not implemented by class com.senocular.display:TransformTool
I see that UIComponent implements this interface, but I had never had this error before, I'm assuming UIComponent should made this implementation by default, so it should be something else, I already try to recreate the project or clean it, with no result, can someone please point me how maybe this can be fix, thanks for your help
oh btw I had this project before in flex builder, exported as a FXP and imported in Flash Builder, thanks!
All UI objects use an Automation delegate to handle implementation of the automation interface. Each UIComponent has a specific automation delegate registered with the Automation Framework. These automation delegate implementations are injected into the object by the Automation framework when the object is created according to the class name of the object.
For example:
UIComponent <- UIComponentAutomationImpl
ToolTip <- ToolTipAutomationImpl
DateChooser <- DateChooserAutomationImpl
Normally if you subclass a component you should inherit the Automation Implementation. However depending upon how the instances of the object are being created the automation framework may not be able to resolve the class name to the appropriate super class. In this case you may need to take additional steps to get the automation implementation into your class.
If you want your class to automatically be injected with a particulary automation implementation you should call the static registerDelegateClass method on the mx.automation.Automation class.
import mx.automation.*
Automation.registerDelegateClass(com.foo.bar.ArtWorkImage, mx.automation.delelegates.core.UIComponentAutomationImpl);
Alternatively you could directly implement the IAutomationObject methods in your UIComponent or create your own delegate class and instantiate and "inject" it into your class in its' constructor thereby by passing the Automation framework.
Here are few links that might help you understand the automation framework:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/automation/Automation.html
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/automation/delegates/core/UIComponentAutomationImpl.html
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/automation/package-detail.html