define ב- JAVA

capslock1

New member
define ב- JAVA

שלום, אני מגיע מתחום של תיכנות בשפת C. בשפת C קימת אפשרות להגדיר define כשבכל מופע יוחלף רצף התויים. האם קיים כזה define גם בשפת JAVA ?
 

voguemaster

New member
לא

בג'אווה לא קיים DEFINE כי DEFINE זה ב-90 אחוז דבר גרוע מאוד. לכן, רצוי שתתרגל לעבוד עם קבועים
 

vinney

Well-known member
כן

אני אומנם לא איש ג'אווה אלא ++C\C, אבל אני גם חושב שDEFINEים ומאקרואים עבר זמנם כשיש קבועים ופונקציות inline.
 

desertboy

New member
לא בדיוק

הרי inline הוא בגדר המלצה בלבד לקומפיילר , ומה לעשות יש מצבים שזה לא מספיק .
 

vinney

Well-known member
מה פתאום?

הרי לך מהתנ"ך הסבר:
The inline keyword tells the compiler that inline expansion is preferred. However, the compiler can create a separate instance of the function (instantiate) and create standard calling linkages instead of inserting the code inline. Two cases where this can happen are: Recursive functions. Functions that are referred to through a pointer elsewhere in the translation unit.​
בשני המקרים האלה אתה ממילא לא יכול להשתמש במקרו
 

Zack DA

New member
מן הסתם לא.

ב- Java יש רק קבועים. Define זה דבר מגעיל ומועד לפורענות...
 
למעלה