Skip to content

How to replace final field #1830

@dep4

Description

@dep4

Rafael,

I tried to find an answer to this question for a long time but so far only found MemberSubstitution, which replaces access but not the definition. If you could please point me into the right direction?

Replace

class ClassA {
  static final ClassB field=new ClassB(1)
}

with

class ClassA {
  static final ClassB field=new ClassB(2)
}

One use case is to replace field in interface so reflection and setting in construction would not apply there.

I'm saving bytecode to file rather that injecting if that lifts any restrictions. If that's only possible with ASM, is there an approximate example?

Many thanks

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions