Author Topic: Prevent generation of "finalize()" methods?  (Read 660 times)

pstein

  • EA User
  • **
  • Posts: 44
  • Karma: +0/-0
    • View Profile
Prevent generation of "finalize()" methods?
« on: November 03, 2010, 06:51:33 pm »
Assume I have a data class diagram and generate appropriate Java Classes from it.

Unfortunately all java classes contain "finalize()" methods.

How can I tell EA to NOT generate those methods?

Peter

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 9392
  • Karma: +258/-27
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Prevent generation of "finalize()" methods?
« Reply #1 on: November 03, 2010, 07:21:10 pm »
I think Tools/Options/Source Code Engineering/Object Lifetimes and then deselect Generate Destructor.

Geert

ajaimes

  • EA Novice
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
    • Andres Jaimes
Re: Prevent generation of "finalize()" methods?
« Reply #2 on: August 03, 2018, 01:06:17 am »
Yes. There are two ways to do it:

Option 1: Disabling constructor and destructor generation class by class. Right click on your class > Code Engineering > Generate Code > Advanced > Object Lifetimes. Uncheck Generate Constructor and Generate Destructor.

Option 2: Modifying the Java code generation templates. Go to the Package menu > Code Engineering > Code Generation Templates... > Language Java > Class Body and remove the following two sections:

Code: [Select]
$ops=""
%if genOptGenConstructor == "T" and classHasConstructor != "T"%
$ops+="\tpublic "+%className%+"(){\n\n\t}"
%endIf%

and

Code: [Select]
%if genOptGenDestructor == "T" and classHasDestructor != "T"%
$ops+="\n\n\tpublic void finalize() throws Throwable {\n"
$ops+=%classHasParent=="T" ? "\t\tsuper.finalize();" : ""% + "\n\t}"
%endIf%