INRIA / INRIA/spoon

Generics Type Variable Resolution

Open
#5,131 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
2k
Forks
392
Avg merge
11h 24m
Merged PRs (30d)
36

Description

consider the following

```java
class Generic {
public T field;
}

class UseGeneric extends Generic {
public Generic f;
}
```

is there a way, via TypeFactory (reflection), to obtain `UseGeneric.field` with `T` resolved to the correct type (String)?

the intent is for type resolution of Generics without knowing in advanced what the Type Variable actually is, but being infered from some root class such as `UseGeneric`

eg

`UseGeneric` would resolve

```java
UseGeneric u = new UseGeneric();
u.field == String
u.f.field == Integer
```

either by supplying `UseGeneric.class` or by converting `UseGeneric.class` into abstract source code (with no decompilation of method bodies as we do not need them) which is then analyzed by spoon's java code type analyser to obtain correct types

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.