• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How pattern works?

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

hi,
can anybody please help me out in the below mentioned factors

1)how the pattern works ? is it a abstract class or singleton class?

2)the part // 1 " st.mt1.find();" which calls the method find() returns a Boolean value true or false .
but the return of this method is not assigned to any variable ? Then how this works ?

Thanks in Advance


 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

AshutoshP Patil wrote:1)how the pattern works ? is it a abstract class or singleton class?


Not sure what you're asking here. Pattern is a class, it has static methods, it has instance methods, like many other classes.

2)the part // 1 " st.mt1.find();" which calls the method find() returns a Boolean value true or false .
but the return of this method is not assigned to any variable ? Then how this works ?


Just because a method returns a variable doesn't mean it has to be used.
 
AshutoshP Patil
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

@david just because the method returns the variable it has to be used



my point is since this function is returning a Boolean value , it must be contained into a variable.(may or may not be used)

 
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

AshutoshP Patil wrote:
my point is since this function is returning a Boolean value , it must be contained into a variable.(may or may not be used)



No, actually it doesn't. The JVM will happily toss out values and references that you don't assign.

John.
 
AshutoshP Patil
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ok i got. thanks john.
can you please go ahead how this compile method works ?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why *wouldn't* it work? Have you looked at the Matcher docs?
 
AshutoshP Patil
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my doubt is how the compile method can take two values
one when it is passed as actual argument
another after passed to method " st.pt1=((Pattern)ob).compile(s[0]);"

will it modify upon the previous pattern instance?

thanks for reply.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm still not sure what you're asking, sorry.
 
Ranch Hand
Posts: 82
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

my doubt is how the compile method can take two values
one when it is passed as actual argument
another after passed to method " st.pt1=((Pattern)ob).compile(s[0]);"



compile is not taking two values, in the code ob1 is an instance of Pattern created using the Pattern method "compile(String regex)" then in the method getFormattedObject, the if statement determines that the object is an instance of Pattern. if true, then the Stores object pt1 will equal a Pattern object resulting from the compile(s[0]) or compile("H[a-b][k-m").

Larry
 
AshutoshP Patil
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks i got.
 
reply
    Bookmark Topic Watch Topic
  • New Topic