Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
H1694942638
Contributor II
Contributor II

defining a class in routines & instantiate it in tJava without static functions

Hello,

I wonder if I can create a class with non-static functions (in routines) and instantiate an instance of the class in a t_java component & use its functions?

I'm not sure if this is considered good practice or even a valid one. However, I have a code that is used in multiple jobs with slight variations, and I believe applying the factory design pattern would be the most suitable solution for this.

Thanks!

Labels (2)
2 Replies
Anonymous
Not applicable

Hello,

Talend Studio allows you to store frequently used parts of code or extract parts of existing functions and then call them via routines. You can call a routine many times from within the same Job or from more than one of your Jobs.

public static void main(..)

You can call any function in any of the system and user routines from your Job components in order to run them at the same time as your Job.

To access all routine functions, press Ctrl+Space in any of the fields in the Basic settings view of a component used in your Job and select the one you want to use from the list displayed.

​As the first triggered method is usually, "public static void main(..)", with your requirement that non-static functions in routines, could you please elaborate your case with an example?

Best regards

Sabrina

H1694942638
Contributor II
Contributor II
Author

 

Hi @Xiaodi Shi​  (Sabrina)

 

> with your requirement that non-static functions in routines, could you please elaborate your case with an example?

 

 

I wish to achieve the following:

 

I have multiple jobs with redundant code. The routines called at each job are mostly the same but with different variations. This redundancy can be reduced by introducing a class, for example, "Processor," with a function called "run" that can call different methods based on the given arguments.

Ultimately, in each job, I need a tJavaComponent that should include these two lines or more:

 

Processor x = new Processor(...);

Double output = x.run();

 

Thanks!