← Back to Scala Course | Chapter 1: Setup & Basics | Lesson 8 of 8

Comments क्या हैं

Comments लोगों के लिए notes होते हैं जिन्हें Scala नज़रअंदाज़ करता है, जैसे किसी recipe पर एक sticky note। वे program का व्यवहार बदले बिना आपकी सोच समझाते हैं।

In this page:

  1. Comments
Syntax
scala
// single-line comment
/* multi-line
   comment */

Comments

Scala में // एक single-line comment शुरू करता है, और /* ... */ एक multi-line comment block को wrap करता है।

Scaladoc comments, जो /** ... */ के रूप में लिखे जाते हैं, API documentation generate करने के लिए उपयोग होते हैं और classes, objects, और methods के ऊपर दिखाई दे सकते हैं। Comments को वह न दोहराकर, जो code पहले से स्पष्ट करता है, गैर-स्पष्ट reasoning समझानी चाहिए।

Note: /** ... */ (double-star) Scaladoc comments को documentation-generation tools पहचानते हैं, साधारण /* ... */ comments के विपरीत।

उदाहरण: Comments

markup
object Main extends App {
  // This is a single-line comment
  val x = 10 // inline comment after code

  /* This is a
     multi-line comment block */

  /** Scaladoc comment describing this value. */
  val y = 20

  println(x + y)
}
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. /* ... /* ... */ ... */ को nest करना और उम्मीद करना कि इसे नज़रअंदाज़ किया जाएगा, जबकि Scala nested comments को support करता है लेकिन missing closing */ बाकी file को comment कर देता है।
  2. comments के लिए अन्य languages की तरह # या -- का उपयोग करना, जबकि Scala // और /* */ उपयोग करता है।
  3. जिस definition को document करना है उससे दूर /** ... */ Scaladoc comment लिखना, जिससे यह किसी से जुड़ता नहीं।
चैप्टर सारांश
  • Scala को installation, REPL, और scripts चलाने के साथ set up किया जाता है, और programs की एक निश्चित structure होती है।
  • object और class मूल building blocks हैं।
  • println, print, और comments output पैदा करते हैं और code को document करते हैं।
🔒

Chapter Quiz — Complete all 8 topics to unlock

0/8 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.