Same interface from multiple type
I have an interface, and there are some implementations for this. Each implementation belongs to some type.
I want that when I'm using autowired I would able to get all the implementation of the certain type. How can I do it?
public interface someInterface{}
public class impl1OfType1 implements someInterface{}
public class impl2OfType1 implements someInterface{}
public class impl1OfType2 implements someInterface{}
public class impl2OfType2 implements someInterface{}
public class someClass{
@autowired
public someClass(List<someInterface> interfaceList){}
}
I want to get only impl1OfType1 and impl2OfType1. And not all the implementation.
And at other place I want to get only impl1OfType2 and impl2OfType2.
more concrete example -
public interface EntityCreator{
createEntity();
}
@Component
public class DogCreator implements entityCreator{}
@Component
public class CatCreator implements entityCreator{}
@Component
public class CarCreator implements entityCreator{}
@Component
public class TruckCreator implements entityCreator{}
@Component
public class AnimalsFactory{
@Autowired
public AnimalsFactory(List<EntityCreator> creators){}
}
java spring dependency-injection autowired
add a comment |
I have an interface, and there are some implementations for this. Each implementation belongs to some type.
I want that when I'm using autowired I would able to get all the implementation of the certain type. How can I do it?
public interface someInterface{}
public class impl1OfType1 implements someInterface{}
public class impl2OfType1 implements someInterface{}
public class impl1OfType2 implements someInterface{}
public class impl2OfType2 implements someInterface{}
public class someClass{
@autowired
public someClass(List<someInterface> interfaceList){}
}
I want to get only impl1OfType1 and impl2OfType1. And not all the implementation.
And at other place I want to get only impl1OfType2 and impl2OfType2.
more concrete example -
public interface EntityCreator{
createEntity();
}
@Component
public class DogCreator implements entityCreator{}
@Component
public class CatCreator implements entityCreator{}
@Component
public class CarCreator implements entityCreator{}
@Component
public class TruckCreator implements entityCreator{}
@Component
public class AnimalsFactory{
@Autowired
public AnimalsFactory(List<EntityCreator> creators){}
}
java spring dependency-injection autowired
2
a classimplementsan interface, notextendsit
– Andrew Tobilko
Dec 31 '18 at 12:00
2
Please read about Java naming conventions. Class names go UpperCase always!
– GhostCat
Dec 31 '18 at 12:01
1
Given what you posted, you should get nothing at all since none of the classes is annotated with@Component. Post a complete minimal example reproducing the problem, otherwise all we can do is guess what the problem might be.
– JB Nizet
Dec 31 '18 at 12:07
@eliranyosef Please be accurate with the edits, 2CarCreators and@autowiredmake little sense
– Andrew Tobilko
Dec 31 '18 at 12:39
add a comment |
I have an interface, and there are some implementations for this. Each implementation belongs to some type.
I want that when I'm using autowired I would able to get all the implementation of the certain type. How can I do it?
public interface someInterface{}
public class impl1OfType1 implements someInterface{}
public class impl2OfType1 implements someInterface{}
public class impl1OfType2 implements someInterface{}
public class impl2OfType2 implements someInterface{}
public class someClass{
@autowired
public someClass(List<someInterface> interfaceList){}
}
I want to get only impl1OfType1 and impl2OfType1. And not all the implementation.
And at other place I want to get only impl1OfType2 and impl2OfType2.
more concrete example -
public interface EntityCreator{
createEntity();
}
@Component
public class DogCreator implements entityCreator{}
@Component
public class CatCreator implements entityCreator{}
@Component
public class CarCreator implements entityCreator{}
@Component
public class TruckCreator implements entityCreator{}
@Component
public class AnimalsFactory{
@Autowired
public AnimalsFactory(List<EntityCreator> creators){}
}
java spring dependency-injection autowired
I have an interface, and there are some implementations for this. Each implementation belongs to some type.
I want that when I'm using autowired I would able to get all the implementation of the certain type. How can I do it?
public interface someInterface{}
public class impl1OfType1 implements someInterface{}
public class impl2OfType1 implements someInterface{}
public class impl1OfType2 implements someInterface{}
public class impl2OfType2 implements someInterface{}
public class someClass{
@autowired
public someClass(List<someInterface> interfaceList){}
}
I want to get only impl1OfType1 and impl2OfType1. And not all the implementation.
And at other place I want to get only impl1OfType2 and impl2OfType2.
more concrete example -
public interface EntityCreator{
createEntity();
}
@Component
public class DogCreator implements entityCreator{}
@Component
public class CatCreator implements entityCreator{}
@Component
public class CarCreator implements entityCreator{}
@Component
public class TruckCreator implements entityCreator{}
@Component
public class AnimalsFactory{
@Autowired
public AnimalsFactory(List<EntityCreator> creators){}
}
java spring dependency-injection autowired
java spring dependency-injection autowired
edited Dec 31 '18 at 12:53
Andrew Tobilko
27.4k104285
27.4k104285
asked Dec 31 '18 at 11:56
eliran yosefeliran yosef
212
212
2
a classimplementsan interface, notextendsit
– Andrew Tobilko
Dec 31 '18 at 12:00
2
Please read about Java naming conventions. Class names go UpperCase always!
– GhostCat
Dec 31 '18 at 12:01
1
Given what you posted, you should get nothing at all since none of the classes is annotated with@Component. Post a complete minimal example reproducing the problem, otherwise all we can do is guess what the problem might be.
– JB Nizet
Dec 31 '18 at 12:07
@eliranyosef Please be accurate with the edits, 2CarCreators and@autowiredmake little sense
– Andrew Tobilko
Dec 31 '18 at 12:39
add a comment |
2
a classimplementsan interface, notextendsit
– Andrew Tobilko
Dec 31 '18 at 12:00
2
Please read about Java naming conventions. Class names go UpperCase always!
– GhostCat
Dec 31 '18 at 12:01
1
Given what you posted, you should get nothing at all since none of the classes is annotated with@Component. Post a complete minimal example reproducing the problem, otherwise all we can do is guess what the problem might be.
– JB Nizet
Dec 31 '18 at 12:07
@eliranyosef Please be accurate with the edits, 2CarCreators and@autowiredmake little sense
– Andrew Tobilko
Dec 31 '18 at 12:39
2
2
a class
implements an interface, not extends it– Andrew Tobilko
Dec 31 '18 at 12:00
a class
implements an interface, not extends it– Andrew Tobilko
Dec 31 '18 at 12:00
2
2
Please read about Java naming conventions. Class names go UpperCase always!
– GhostCat
Dec 31 '18 at 12:01
Please read about Java naming conventions. Class names go UpperCase always!
– GhostCat
Dec 31 '18 at 12:01
1
1
Given what you posted, you should get nothing at all since none of the classes is annotated with
@Component. Post a complete minimal example reproducing the problem, otherwise all we can do is guess what the problem might be.– JB Nizet
Dec 31 '18 at 12:07
Given what you posted, you should get nothing at all since none of the classes is annotated with
@Component. Post a complete minimal example reproducing the problem, otherwise all we can do is guess what the problem might be.– JB Nizet
Dec 31 '18 at 12:07
@eliranyosef Please be accurate with the edits, 2
CarCreators and @autowired make little sense– Andrew Tobilko
Dec 31 '18 at 12:39
@eliranyosef Please be accurate with the edits, 2
CarCreators and @autowired make little sense– Andrew Tobilko
Dec 31 '18 at 12:39
add a comment |
2 Answers
2
active
oldest
votes
The solution would be using @Qualifier.
@Component
@Qualifier("place1")
class Impl1OfType2 implements SomeInterface {}
@Component
@Qualifier("place1")
class Impl2OfType2 implements SomeInterface {}
@Service
class SomeClass {
@Autowired
public SomeClass(@Qualifier("place1") List<SomeInterface> interfaceList) {
System.out.println(interfaceList);
}
}
I slightly changed the names to adhere to the Java convention. They are still a bit awkward and contextless.
UPDATE
You might use generics, Spring is good at dealing with them. For instance, it will inject only DogCreator and CatCreator into a List<EntityCreator<Animal>>.
interface Animal {}
interface Machine {}
interface EntityCreator<T> {}
@Component
class DogCreator implements EntityCreator<Animal> {}
@Component
class CatCreator implements EntityCreator<Animal> {}
@Component
class CarCreator implements EntityCreator<Machine> {}
@Component
class TruckCreator implements EntityCreator<Machine> {}
@Component
class AnimalsFactory {
@Autowired
public AnimalsFactory(List<EntityCreator<Animal>> creators) { }
}
UPDATE 2
You could write marker interfaces which would break down existing implementations into logical groups.
interface AnimalCreator {}
interface EntityCreator<T> {}
@Component
class DogCreator implements EntityCreator, AnimalCreator {}
@Component
class CatCreator implements EntityCreator, AnimalCreator {}
@Component
class AnimalsFactory {
@Autowired
public AnimalsFactory(List<AnimalCreator> creators) {
System.out.println(creators);
}
}
Thank you for the solution I had think about this idea, but I don't want that each one who will create implementation to interface should add qualifier. How can I do it?
– eliran yosef
Dec 31 '18 at 12:27
@eliranyosef Spring operates on presented meta-information, I don't think there's any different to tell Spring filter out candidates for autowiring.
– Andrew Tobilko
Dec 31 '18 at 12:30
@eliranyosef you may write another interface which would be shared by the interfaces that are supposed to be used in the same place.
– Andrew Tobilko
Dec 31 '18 at 12:32
add a comment |
If you correct your code with above comments and I understand your problem, I assume this can be a way to solve your issue.
public interface Someinterface<T extends someType> {}
public class someType{}
public class Type1 extends someType{}
public class Type2 extends someType{}
public class TypedInterface1 implements Someinterface<Type1> {}
public class TypedInterface2 implements Someinterface<Type2> {}
public class someClass{
@Autowired
public someClass(List<TypedInterface1> interfaceList){}
}
Let me know if I answered your question.
your answer absolutely makes no sense to me. Compare your code to OP's. I downvoted.
– Andrew Tobilko
Dec 31 '18 at 12:17
In OP post, the type cannot be deduced because of multiple implementations of Someinterface. In my solution however Type inference is not a problem. So DI framework should have no issue injecting the correct implementation. However I have just begin in JAVA from C++ and may have misunderstood something.
– Akshay Mathur
Dec 31 '18 at 12:22
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53987208%2fsame-interface-from-multiple-type%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The solution would be using @Qualifier.
@Component
@Qualifier("place1")
class Impl1OfType2 implements SomeInterface {}
@Component
@Qualifier("place1")
class Impl2OfType2 implements SomeInterface {}
@Service
class SomeClass {
@Autowired
public SomeClass(@Qualifier("place1") List<SomeInterface> interfaceList) {
System.out.println(interfaceList);
}
}
I slightly changed the names to adhere to the Java convention. They are still a bit awkward and contextless.
UPDATE
You might use generics, Spring is good at dealing with them. For instance, it will inject only DogCreator and CatCreator into a List<EntityCreator<Animal>>.
interface Animal {}
interface Machine {}
interface EntityCreator<T> {}
@Component
class DogCreator implements EntityCreator<Animal> {}
@Component
class CatCreator implements EntityCreator<Animal> {}
@Component
class CarCreator implements EntityCreator<Machine> {}
@Component
class TruckCreator implements EntityCreator<Machine> {}
@Component
class AnimalsFactory {
@Autowired
public AnimalsFactory(List<EntityCreator<Animal>> creators) { }
}
UPDATE 2
You could write marker interfaces which would break down existing implementations into logical groups.
interface AnimalCreator {}
interface EntityCreator<T> {}
@Component
class DogCreator implements EntityCreator, AnimalCreator {}
@Component
class CatCreator implements EntityCreator, AnimalCreator {}
@Component
class AnimalsFactory {
@Autowired
public AnimalsFactory(List<AnimalCreator> creators) {
System.out.println(creators);
}
}
Thank you for the solution I had think about this idea, but I don't want that each one who will create implementation to interface should add qualifier. How can I do it?
– eliran yosef
Dec 31 '18 at 12:27
@eliranyosef Spring operates on presented meta-information, I don't think there's any different to tell Spring filter out candidates for autowiring.
– Andrew Tobilko
Dec 31 '18 at 12:30
@eliranyosef you may write another interface which would be shared by the interfaces that are supposed to be used in the same place.
– Andrew Tobilko
Dec 31 '18 at 12:32
add a comment |
The solution would be using @Qualifier.
@Component
@Qualifier("place1")
class Impl1OfType2 implements SomeInterface {}
@Component
@Qualifier("place1")
class Impl2OfType2 implements SomeInterface {}
@Service
class SomeClass {
@Autowired
public SomeClass(@Qualifier("place1") List<SomeInterface> interfaceList) {
System.out.println(interfaceList);
}
}
I slightly changed the names to adhere to the Java convention. They are still a bit awkward and contextless.
UPDATE
You might use generics, Spring is good at dealing with them. For instance, it will inject only DogCreator and CatCreator into a List<EntityCreator<Animal>>.
interface Animal {}
interface Machine {}
interface EntityCreator<T> {}
@Component
class DogCreator implements EntityCreator<Animal> {}
@Component
class CatCreator implements EntityCreator<Animal> {}
@Component
class CarCreator implements EntityCreator<Machine> {}
@Component
class TruckCreator implements EntityCreator<Machine> {}
@Component
class AnimalsFactory {
@Autowired
public AnimalsFactory(List<EntityCreator<Animal>> creators) { }
}
UPDATE 2
You could write marker interfaces which would break down existing implementations into logical groups.
interface AnimalCreator {}
interface EntityCreator<T> {}
@Component
class DogCreator implements EntityCreator, AnimalCreator {}
@Component
class CatCreator implements EntityCreator, AnimalCreator {}
@Component
class AnimalsFactory {
@Autowired
public AnimalsFactory(List<AnimalCreator> creators) {
System.out.println(creators);
}
}
Thank you for the solution I had think about this idea, but I don't want that each one who will create implementation to interface should add qualifier. How can I do it?
– eliran yosef
Dec 31 '18 at 12:27
@eliranyosef Spring operates on presented meta-information, I don't think there's any different to tell Spring filter out candidates for autowiring.
– Andrew Tobilko
Dec 31 '18 at 12:30
@eliranyosef you may write another interface which would be shared by the interfaces that are supposed to be used in the same place.
– Andrew Tobilko
Dec 31 '18 at 12:32
add a comment |
The solution would be using @Qualifier.
@Component
@Qualifier("place1")
class Impl1OfType2 implements SomeInterface {}
@Component
@Qualifier("place1")
class Impl2OfType2 implements SomeInterface {}
@Service
class SomeClass {
@Autowired
public SomeClass(@Qualifier("place1") List<SomeInterface> interfaceList) {
System.out.println(interfaceList);
}
}
I slightly changed the names to adhere to the Java convention. They are still a bit awkward and contextless.
UPDATE
You might use generics, Spring is good at dealing with them. For instance, it will inject only DogCreator and CatCreator into a List<EntityCreator<Animal>>.
interface Animal {}
interface Machine {}
interface EntityCreator<T> {}
@Component
class DogCreator implements EntityCreator<Animal> {}
@Component
class CatCreator implements EntityCreator<Animal> {}
@Component
class CarCreator implements EntityCreator<Machine> {}
@Component
class TruckCreator implements EntityCreator<Machine> {}
@Component
class AnimalsFactory {
@Autowired
public AnimalsFactory(List<EntityCreator<Animal>> creators) { }
}
UPDATE 2
You could write marker interfaces which would break down existing implementations into logical groups.
interface AnimalCreator {}
interface EntityCreator<T> {}
@Component
class DogCreator implements EntityCreator, AnimalCreator {}
@Component
class CatCreator implements EntityCreator, AnimalCreator {}
@Component
class AnimalsFactory {
@Autowired
public AnimalsFactory(List<AnimalCreator> creators) {
System.out.println(creators);
}
}
The solution would be using @Qualifier.
@Component
@Qualifier("place1")
class Impl1OfType2 implements SomeInterface {}
@Component
@Qualifier("place1")
class Impl2OfType2 implements SomeInterface {}
@Service
class SomeClass {
@Autowired
public SomeClass(@Qualifier("place1") List<SomeInterface> interfaceList) {
System.out.println(interfaceList);
}
}
I slightly changed the names to adhere to the Java convention. They are still a bit awkward and contextless.
UPDATE
You might use generics, Spring is good at dealing with them. For instance, it will inject only DogCreator and CatCreator into a List<EntityCreator<Animal>>.
interface Animal {}
interface Machine {}
interface EntityCreator<T> {}
@Component
class DogCreator implements EntityCreator<Animal> {}
@Component
class CatCreator implements EntityCreator<Animal> {}
@Component
class CarCreator implements EntityCreator<Machine> {}
@Component
class TruckCreator implements EntityCreator<Machine> {}
@Component
class AnimalsFactory {
@Autowired
public AnimalsFactory(List<EntityCreator<Animal>> creators) { }
}
UPDATE 2
You could write marker interfaces which would break down existing implementations into logical groups.
interface AnimalCreator {}
interface EntityCreator<T> {}
@Component
class DogCreator implements EntityCreator, AnimalCreator {}
@Component
class CatCreator implements EntityCreator, AnimalCreator {}
@Component
class AnimalsFactory {
@Autowired
public AnimalsFactory(List<AnimalCreator> creators) {
System.out.println(creators);
}
}
edited Dec 31 '18 at 12:51
answered Dec 31 '18 at 12:07
Andrew TobilkoAndrew Tobilko
27.4k104285
27.4k104285
Thank you for the solution I had think about this idea, but I don't want that each one who will create implementation to interface should add qualifier. How can I do it?
– eliran yosef
Dec 31 '18 at 12:27
@eliranyosef Spring operates on presented meta-information, I don't think there's any different to tell Spring filter out candidates for autowiring.
– Andrew Tobilko
Dec 31 '18 at 12:30
@eliranyosef you may write another interface which would be shared by the interfaces that are supposed to be used in the same place.
– Andrew Tobilko
Dec 31 '18 at 12:32
add a comment |
Thank you for the solution I had think about this idea, but I don't want that each one who will create implementation to interface should add qualifier. How can I do it?
– eliran yosef
Dec 31 '18 at 12:27
@eliranyosef Spring operates on presented meta-information, I don't think there's any different to tell Spring filter out candidates for autowiring.
– Andrew Tobilko
Dec 31 '18 at 12:30
@eliranyosef you may write another interface which would be shared by the interfaces that are supposed to be used in the same place.
– Andrew Tobilko
Dec 31 '18 at 12:32
Thank you for the solution I had think about this idea, but I don't want that each one who will create implementation to interface should add qualifier. How can I do it?
– eliran yosef
Dec 31 '18 at 12:27
Thank you for the solution I had think about this idea, but I don't want that each one who will create implementation to interface should add qualifier. How can I do it?
– eliran yosef
Dec 31 '18 at 12:27
@eliranyosef Spring operates on presented meta-information, I don't think there's any different to tell Spring filter out candidates for autowiring.
– Andrew Tobilko
Dec 31 '18 at 12:30
@eliranyosef Spring operates on presented meta-information, I don't think there's any different to tell Spring filter out candidates for autowiring.
– Andrew Tobilko
Dec 31 '18 at 12:30
@eliranyosef you may write another interface which would be shared by the interfaces that are supposed to be used in the same place.
– Andrew Tobilko
Dec 31 '18 at 12:32
@eliranyosef you may write another interface which would be shared by the interfaces that are supposed to be used in the same place.
– Andrew Tobilko
Dec 31 '18 at 12:32
add a comment |
If you correct your code with above comments and I understand your problem, I assume this can be a way to solve your issue.
public interface Someinterface<T extends someType> {}
public class someType{}
public class Type1 extends someType{}
public class Type2 extends someType{}
public class TypedInterface1 implements Someinterface<Type1> {}
public class TypedInterface2 implements Someinterface<Type2> {}
public class someClass{
@Autowired
public someClass(List<TypedInterface1> interfaceList){}
}
Let me know if I answered your question.
your answer absolutely makes no sense to me. Compare your code to OP's. I downvoted.
– Andrew Tobilko
Dec 31 '18 at 12:17
In OP post, the type cannot be deduced because of multiple implementations of Someinterface. In my solution however Type inference is not a problem. So DI framework should have no issue injecting the correct implementation. However I have just begin in JAVA from C++ and may have misunderstood something.
– Akshay Mathur
Dec 31 '18 at 12:22
add a comment |
If you correct your code with above comments and I understand your problem, I assume this can be a way to solve your issue.
public interface Someinterface<T extends someType> {}
public class someType{}
public class Type1 extends someType{}
public class Type2 extends someType{}
public class TypedInterface1 implements Someinterface<Type1> {}
public class TypedInterface2 implements Someinterface<Type2> {}
public class someClass{
@Autowired
public someClass(List<TypedInterface1> interfaceList){}
}
Let me know if I answered your question.
your answer absolutely makes no sense to me. Compare your code to OP's. I downvoted.
– Andrew Tobilko
Dec 31 '18 at 12:17
In OP post, the type cannot be deduced because of multiple implementations of Someinterface. In my solution however Type inference is not a problem. So DI framework should have no issue injecting the correct implementation. However I have just begin in JAVA from C++ and may have misunderstood something.
– Akshay Mathur
Dec 31 '18 at 12:22
add a comment |
If you correct your code with above comments and I understand your problem, I assume this can be a way to solve your issue.
public interface Someinterface<T extends someType> {}
public class someType{}
public class Type1 extends someType{}
public class Type2 extends someType{}
public class TypedInterface1 implements Someinterface<Type1> {}
public class TypedInterface2 implements Someinterface<Type2> {}
public class someClass{
@Autowired
public someClass(List<TypedInterface1> interfaceList){}
}
Let me know if I answered your question.
If you correct your code with above comments and I understand your problem, I assume this can be a way to solve your issue.
public interface Someinterface<T extends someType> {}
public class someType{}
public class Type1 extends someType{}
public class Type2 extends someType{}
public class TypedInterface1 implements Someinterface<Type1> {}
public class TypedInterface2 implements Someinterface<Type2> {}
public class someClass{
@Autowired
public someClass(List<TypedInterface1> interfaceList){}
}
Let me know if I answered your question.
edited Dec 31 '18 at 12:45
Andrew Tobilko
27.4k104285
27.4k104285
answered Dec 31 '18 at 12:09
Akshay MathurAkshay Mathur
88210
88210
your answer absolutely makes no sense to me. Compare your code to OP's. I downvoted.
– Andrew Tobilko
Dec 31 '18 at 12:17
In OP post, the type cannot be deduced because of multiple implementations of Someinterface. In my solution however Type inference is not a problem. So DI framework should have no issue injecting the correct implementation. However I have just begin in JAVA from C++ and may have misunderstood something.
– Akshay Mathur
Dec 31 '18 at 12:22
add a comment |
your answer absolutely makes no sense to me. Compare your code to OP's. I downvoted.
– Andrew Tobilko
Dec 31 '18 at 12:17
In OP post, the type cannot be deduced because of multiple implementations of Someinterface. In my solution however Type inference is not a problem. So DI framework should have no issue injecting the correct implementation. However I have just begin in JAVA from C++ and may have misunderstood something.
– Akshay Mathur
Dec 31 '18 at 12:22
your answer absolutely makes no sense to me. Compare your code to OP's. I downvoted.
– Andrew Tobilko
Dec 31 '18 at 12:17
your answer absolutely makes no sense to me. Compare your code to OP's. I downvoted.
– Andrew Tobilko
Dec 31 '18 at 12:17
In OP post, the type cannot be deduced because of multiple implementations of Someinterface. In my solution however Type inference is not a problem. So DI framework should have no issue injecting the correct implementation. However I have just begin in JAVA from C++ and may have misunderstood something.
– Akshay Mathur
Dec 31 '18 at 12:22
In OP post, the type cannot be deduced because of multiple implementations of Someinterface. In my solution however Type inference is not a problem. So DI framework should have no issue injecting the correct implementation. However I have just begin in JAVA from C++ and may have misunderstood something.
– Akshay Mathur
Dec 31 '18 at 12:22
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53987208%2fsame-interface-from-multiple-type%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
a class
implementsan interface, notextendsit– Andrew Tobilko
Dec 31 '18 at 12:00
2
Please read about Java naming conventions. Class names go UpperCase always!
– GhostCat
Dec 31 '18 at 12:01
1
Given what you posted, you should get nothing at all since none of the classes is annotated with
@Component. Post a complete minimal example reproducing the problem, otherwise all we can do is guess what the problem might be.– JB Nizet
Dec 31 '18 at 12:07
@eliranyosef Please be accurate with the edits, 2
CarCreators and@autowiredmake little sense– Andrew Tobilko
Dec 31 '18 at 12:39