TAILIEUCHUNG - Bắt đầu với IBM Websphere smash - p 38

352 Appendix A Get Started with Groovy Embedded Quotes Quotes can be embedded in strings with Groovy in a natural way. If you want to embed double quotes, you can use single quotes to define the string. Likewise, the same is true if single quotes are to be embedded. Groovy also supports the usual escaping of quotes (see Listing ). Listing Escaping Quotes println 'double "quotes" are easy' println "or \"escape\" them" println "single 'quotes' are easy too" Single and double quotes can be used within heredocs, as shown in Listing . Listing Quotes in Heredocs println """ "double quotes" 'single quotes' """ Getters and Field Pointers When class. | 352 Appendix A Get Started with Groovy Embedded Quotes Quotes can be embedded in strings with Groovy in a natural way. If you want to embed double quotes you can use single quotes to define the string. Likewise the same is true if single quotes are to be embedded. Groovy also supports the usual escaping of quotes see Listing . Listing Escaping Quotes println double quotes are easy println or escape them println single quotes are easy too Single and double quotes can be used within heredocs as shown in Listing . Listing Quotes in Heredocs println double quotes single quotes Getters and Field Pointers When class variables are defined in Groovy we can access those fields using the . dot operator. We can modify that behavior or retrieve the variable by providing our own getter method see Listing . Listing Changing Default Variable Access class BarClass def var this is bar def getVar return var def bar new BarClass println The output from this code would be this is bar . Although this can be useful there may be times when you would want to get access to the fields bypassing the getter. To do this you need to create a field pointer as shown in Listing . Download from Parentheses and Method Pointers 353 Listing Field Pointer class BarClass def var this is bar def getVar return var def bar new BarClass println bar.@var The output of this code is this is bar which is the exact text in the variable bypassing the getter method. We can also assign this field pointer to a variable and use the variable to access the field see Listing . Listing Assigning a Field Pointer to a Variable def varPtr bar.@var println varPtr What might be a bit confusing is that this does not work for setters. We cannot use varPtr to set . Likewise you cannot access a custom setVar method with the dot operator you must explicitly call your custom setVar method. Parentheses and Method Pointers We noted earlier that parentheses are

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.