Home > Back-end >  JAVA injection than using a static method advantage in where
JAVA injection than using a static method advantage in where

Time:01-20

Is can use at any time, make so big trouble injection, how also don't understand, the great god can use simple language to explain, or forwarded some articles can also

CodePudding user response:

refer to the original poster zyq654321 response:
is can use at any time, make so big trouble injection, how also don't understand, the great god can use simple language to explain, or forwarding some articles can also


Static can only use static cannot call non-static, infuse words don't have the limit,

CodePudding user response:

You mean Java Java code injection can be used at any time is said spring annotations such as @ Autowire, initialization when the spring framework parses the annotations, instantiate the annotation object, the default is a singleton object, you can understand as a big hashmap, the key is the attribute name, val is the instance object and the static can be used at any time you say she doesn't call the static method, called static static code block, when the class is initialized automatically load static code block, the spring annotations and the static are essentially initialization code, there is no difference, hope to help you

CodePudding user response:

Learn Java on the first day of accepting the concept of three features, is the Java object-oriented encapsulation, inheritance, polymorphism, handle to a static method is a class, the characteristics of object-oriented he all have no, injection is an object, so the injection with object-oriented feature.
Your problem can be simplified into a static method and the general method of difference, find the contradiction of things is the important of learning ability, inject the fooled you.

CodePudding user response:

refer to the second floor is called practice response:
you mean Java Java code injection can be used at any time is said spring annotations such as @ Autowire, initialization when the spring framework parses the annotations, instantiate the annotation object, the default is a singleton object, you can understand as a big hashmap, the key is the attribute name, val is the instance object and the static can be used at any time you say she doesn't call the static method, called static static code block, when the class is initialized automatically load static code block, the spring annotations and the static are essentially initialization code, there is no difference, I hope it can help you

The static method and the general method of difference lies in the difference of object oriented, initialization is just a function, completely unable to get the design for this level.

CodePudding user response:

He said, the srping management bean is a proxy class

CodePudding user response:

reference 4 floor maradona1984 response:
Quote: refer to the second floor is called practice response:
you mean Java Java code injection can be used at any time is said spring annotations such as @ Autowire, initialization when the spring framework parses the annotations, instantiate the annotation object, the default is a singleton object, you can understand as a big hashmap, the key is the attribute name, val is the instance object and the static can be used at any time you say she doesn't call the static method, called static static code block, when the class is initialized automatically load static code block, the spring annotations and the static are essentially initialization code, there is no difference, I hope it can help you

The static method and the general method of difference lies in the difference of object oriented, initialization is just one function, completely unable to get the design for this level.

Look from the description of the building Lord, likely he said Java only reflect on the set or ordinary methods, well, may be I think more .

CodePudding user response:

This is the difference between static and non-static object, the distinction is needless to say, has nothing to do with injection
As to why the need to inject, because can let the container to help you manage the class without the need to manually to the new (can, to some extent avoid null pointer object is not new and error, so to some extent can only focus on logic regardless if the object without initialization of exception handling)

CodePudding user response:

refer to the eighth floor qybao response:
this is the difference between static and non-static object, the distinction is needless to say, has nothing to do with injection
As to why the need to inject, because can let the container to help you manage the class without the need to manually to the new (can, to some extent avoid null pointer object is not new and error, so to some extent can only focus on logic regardless if the object without exception handling) resulted from the initialization of

In fact, I found that I want to know what injection should be than new have what advantage, is said to be the injection will only apply for a memory, the static class or method also can only apply for a memory
  • Related