Question: I have set the variable "spring.profiles.active" in my environment to "test" and I have below file in my src/main/resources.

**application-test.properties**

It has one property "machine"

```
machineName=mumbai

```

I want to access this property in one of my Java based class.

```
package com.test.service;

@Component
@RequiredArgsConstructor
public class TestMachine {

    @Value("${machineName}")
    private String machineName;

    @Override
    public void checkMachine() {
        System.out.println(machineName);
    }
}

```

**PropertiesConfig class:**

```
@Configuration
public class PropertiesUtils {

    public static void initProperties() {
        String activeProfile = System.getProperty("spring.profiles.active");
        if (activeProfile == null) {
            activeProfile = "test";
        }
        PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
        Resource[] resources = new ClassPathResource[] {new ClassPathResource("application.properties"),
                        new ClassPathResource("application-" + activeProfile + ".properties")};
        propertySourcesPlaceholderConfigurer.setLocations(resources);
    }
}

```

But while running this as a Spring boot application in Eclipse. I am getting below error:

```
Error creating bean with name 'TestMachine': Injection of autowired dependencies failed;

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'machineName' in value "${machineName}" at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:180) ~[spring-core-5.3.9.jar:5.3.9]

```

What am I missing? I found this way only in most of the websites.

Answer: 
I did some searching and reading. What I want to achieve requires so called "sum types". Currently Go does not support sum types. However, there are few alternative to simulate the behavior of sum types. They are quite nicely described here [Alternatives to sum types in Go](https://making.pusher.com/alternatives-to-sum-types-in-go/).

What is more, it looks like sum types will probably be supported in the Go 2. Further reading [proposal: spec: add sum types / discriminated unions](https://github.com/golang/go/issues/19412), [spec: generics: use type sets to remove type keyword in constraints](https://github.com/golang/go/issues/45346).
What you seem to be expecting is `subtype polymorphism`. Go does not support dynamic binding for non-interface types. Therefore you you could either use interfaces

```
package main

func main(){
    var bar Bar
    var foo Foo
    foo.Symbols = append(foo.Symbols, bar)
}

type Symbol interface {
    Symbol()
}

type Base struct {
    a int32
}

func (b Base)Symbol(){}

type Foo struct {
    Base
    b int32
    Symbols []Symbol
}

type Bar struct {
    Base
    c int32
}

```

or if you dislike using interfaces, you can use a trick like below with reflect.

```
package main

import "fmt"

func main(){
    var bar Bar
    var foo Foo
    err := foo.AddSymbol(bar)
    if err != nil{
        fmt.Println(err)
    }
}

type Base struct {
    a int32
}

func (b Base)Symbol(){}

type Foo struct {
    Base
    b int32
    symbol []interface{} // field made private
}

// AddSymbol : helper to append values
func (f *Foo)AddSymbol(in interface{})(err error){
    if f.symbol == nil{
        f.symbol = make([]interface{},0)
    }

    switch typ := in.(type) {
    case Base,Bar,Foo:
        f.symbol = append(f.symbol,in)
    default:
        return fmt.Errorf("provided type: %s is not supported",typ)
    }

    return nil
}

type Bar struct {
    Base
    c int32
}

```